asp.net mvc - HttpPost vs HttpGet attributes in MVC: Why use HttpPost? -


Then we have [HTTP post], which is an optional feature. I understand that this calls restrict, so this can only be done by requesting an HTTP post. My question is why would I like to do this?

Imagine the following:

  [HttpGet] Public Activity Int ID ... {...} [httpOost] Public Action Result Edit (Myadit Vivamodel My Edit Vimodel) {...}   

This will not be possible unless html gate and http post where it was used makes it really easy to create editing scenes. All action links, just reverse the controller. If the visual model confirms false, you are back in the editing scene right now.

I will be bold and say that this is the best practice when it comes to things in ASP.NET MVC.

Edit:

@theleite asked what is needed to complete the post, this method is just a form with the method.

Using a razor, it will look something like this.

  @using (Html.BeginForm ()) {& lt; Input type = "text" placeholder = "enter email" name = "email" /> & Lt; Input type = "submit" value = "sign up" /> }   

This provides the following HTML:

  & lt; Form action = "/ MyController / edit" method = "post" & gt; & Lt; Input type = "text" name = "email" placeholder = "enter email" & gt; & Lt; Input type = "submit" value = "sign up" & gt; & Lt; / Form & gt;   

When the form is submitted, it requests the HTTTP post to the controller. Action will handle the handle with the HttpPost attribute.

Comments