Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mvc - [HttpPost/HttpGet] vs. [AcceptVerbs(HttpVerbs.Post/Get)]

Tags:

asp.net-mvc

are these things the same?

[HttpPost/HttpGet] vs. [AcceptVerbs(HttpVerbs.Post/Get)] 

if not where is a difference?

like image 908
r.r Avatar asked Jan 20 '11 08:01

r.r


People also ask

What is difference between HttpGet and HttpPost in MVC?

HTTPGet method creates a query string of the name-value pair whereas HTTPPost method passes the name and value pairs in the body of the HTTP request. 3. HTTPGet request has limited length and mostly it is limited to 255 characters long whereas HTTPPost request has no maximum limit.

What is HttpGet HttpGet HttpPut HttpDelete and HttpPost?

The MVC framework includes HttpGet, HttpPost, HttpPut, HttpDelete, HttpOptions, and HttpPatch action verbs. You can apply one or more action verbs to an action method to handle different HTTP requests. If you don't apply any action verbs to an action method, then it will handle HttpGet request by default.

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.

What is the HttpPost action verb in MVC?

HTTP Post. This verb is used while we have to create a new resource in the database. In HttpPost, data travels in the URL and body. To use HttpPost method, we use HttpPost attribute on the Action method.


1 Answers

Yes, absolutely the same. [HttpPost/HttpGet] were introduced in ASP.NET MVC 2 to reduce the keystrokes we have to type :-) [AcceptVerbs(HttpVerbs.Post/Get)] could still be used and behave the same although if you are writing new code I would recommend the first.

like image 106
Darin Dimitrov Avatar answered Sep 18 '22 19:09

Darin Dimitrov