1

While referring asp.net mvc I got stuck on Accept verbs. I know Accept verbs are used for polymorphism in mvc but how do they work ? I think there are 7 Accept verbs in mvc:

  1. HttpVerbs.Get
  2. HttpVerbs.Post
  3. HttpVerbs.Put
  4. HttpVerbs.Delete
  5. HttpVerbs.Head
  6. HttpVerbs.Patch
  7. HttpVerbs.Options

what do they mean and how do they help to make polymorphism in asp.net mvc please help and what are their short hands ( example: [httppost] and [httpget] i knows)

user990423
  • 1,397
  • 2
  • 12
  • 32
  • These are Enumerations for [HTTP Protocol verbs](http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html). – Jasen Sep 10 '15 at 19:05

1 Answers1

3

Delete: Requests that a specified URI be deleted.

Get: Retrieves the information or entity that is identified by the URI of the request.

Head: Retrieves the message headers for the information or entity that is identified by the URI of the request.

Options: Represents a request for information about the communication options available on the request/response chain identified by the Request-URI.

Patch: Requests that a set of changes described in the request entity be applied to the resource identified by the Request- URI.

Post: Posts a new entity as an addition to a URI.

Put: Replaces an entity that is identified by a URI.

Source

Also you can use [AcceptVerbs] to accept other verbs that are not part of the HttpVerbs enum - eg. [AcceptVerbs("Trace")]

Update: actually attributes are examples of AOP used within the .NET framework. So those attributes are some built-in implementations that handles HTTP stuff for you so you don’t have to put those code in all of your controller action methods.

Aspect-oriented Programming and Code Contracts in ASP.NET MVC

Aspect Oriented Programming in ASP.NET MVC

Community
  • 1
  • 1
Sirwan Afifi
  • 10,654
  • 14
  • 63
  • 110
  • 2
    You omitted the link to the [MSDN AcceptVerbs documentation](https://msdn.microsoft.com/en-us/library/system.web.mvc.httpverbs(v=vs.118).aspx), which pretty much covers it. Why people don't look at the documentation before coming here is beyond me. – NightOwl888 Sep 10 '15 at 14:29
  • @NightOwl888 Thanks, I've added the source. – Sirwan Afifi Sep 10 '15 at 14:31
  • 3
    @SirwanAfifi thz for your answer but yet i dont understand the core concept about how this attributes help for polymorphism by putting the attributes in front of the action in controller –  Sep 10 '15 at 18:40
  • @Aakashp maybe you could post that as a question and we could all learn - if you do feel free to mention me in comment with link – Mauricio Gracia Gutierrez Jan 07 '16 at 02:40