public IActionResult Create(String UserID) { //do some action }
in view, I am sending parameter with
<a href="/ProductRegistration/[email protected]"></a>
in this method value is shown in the URL I want to not show in the URL how can we send a parameter from the body
my result is localhost:443//Admin/Create/5
I want this type of result localhost:443//Admin/Create
and this create method should receive a parameter can it possible
3
Answers
Mubashir, maybe something like this can help you out:
HTTP allows different methods that are suited for certain actions to be performed on the server. Theoretically
GET
is intended to get resources (such as a web page, but may be a JSON object, too) and hence allows no body at all in the request. While you could misuse custom headers, my advice is to avoid it at any rate possible. Future developers, maybe even your future self, will thank you.POST
requests, on the other hand, allow data to be posted to the server. According to the spec, one should expect the resource to be altered on the server afterwards, I think, but in the real world it’s often misused to transmit login data for quite obvious reasons (you would not want your password to show up in your browser history, which would be the case withGET
requests – which may not hold true anymore since it would not show up with JS HTTP requests, even if the request was aGET
).So you’d have to alter your controller to allow
POST
requests, as Nick said, with theHttpPostAttribute
and replace the link with a form, for links do not allowPOST
requests at all (GET
is the default for the browser).See this question for some more options to use
POST
instead ofGET
in an HTML page (which would eventually be some kind of form in most cases).Removing ID from URL won’t hide it from anyone. Unless you need it in body explicitly due to some other restrictions, I wouldn’t bother. If you want to hide it, consider encrypting your ID or using GUIDs instead if Integers. VS offers
System.Security.Cryptography
so you don’t need to download anything and its AES encryption is considered to be among most secure encryption method commonly used nowadays. But anyway, that was just an advice, now to answer your original problem.In your view, you can do something like this:
Then in your controller, you would have