Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between [AcceptVerbs(HttpVerbs.Post)] and [HttpPost]?

I can decorate an action either with the [AcceptVerbs(HttpVerbs.Post)]/[AcceptVerbs(HttpVerbs.Get)]

[AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(string title) {     // Do Something... } 

or with the [HttpPost]/[HttpGet] attributes

[HttpPost] public ActionResult Create(string title) {     // Do Something... } 

Are they different?

like image 801
Lorenzo Avatar asked Oct 02 '10 00:10

Lorenzo


People also ask

What is HttpGet and HttpPost?

HttpGet and HttpPost are both the methods of posting client data or form data to the server. HTTP is a HyperText Transfer Protocol that is designed to send and receive the data between client and server using web pages.

What is AcceptVerbs?

The [AcceptVerbs] attribute can be applied to action methods in a controller so that the appropriate overloaded method is invoked for a given request. ASP.NET MVC will automatically dispatch a request to the appropriate action method based on the HTTP verb.

Why do we use HttpPost?

POST is an HTTP method designed to send data to the server from an HTTP client. The HTTP POST method requests the web server accept the data enclosed in the body of the POST message. HTTP POST method is often used when submitting login or contact forms or uploading files and images to the server.


1 Answers

[HttpPost] is shorthand for [AcceptVerbs(HttpVerbs.Post)]. The only difference is that you can't use [HttpGet, HttpPost] (and similar) together on the same action. If you want an action to respond to both GETs and POSTs, you must use [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)].

like image 177
Rudresha Parameshappa Avatar answered Oct 12 '22 19:10

Rudresha Parameshappa