I am using MVC C#.
Can somebody give an example on why one would use
[HttpPost/HttpGet]
for an Action. How can an active have both – what is the practical use?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Let’s say you have a
Loginaction which provides the user with a login screen, then receives the user name and password back after the user submits the form:MVC isn’t being given clear instructions on which action is which, even though we can tell by looking at it. If you add [HttpGet] to the first action and [HttpPost] to the section action, MVC clearly knows which action is which.
Why? See Request Methods. Long and short: When a user views a page, that’s a GET request and when a user submits a form, that’s usually a POST request. HttpGet and HttpPost just restrict the action to the applicable request type.
You can also combine the request method attributes if your action serves requests from multiple verbs:
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)].