ActionVerbs:
In this section, you will learn about ActionVerbs selectors attribute.
The ActionVerbs selector is used when you want to control the selection of an action method based on Http request method. For example, you can define two different action methods with the same name but one action method responds to an HTTP Get request and another action method responds to an HTTP Post request.
MVC framework supports different ActionVerbs, such as HttpGet, HttpPost, HttpPut, HttpDelete, HttpOptions & HttpPatch. You can apply these attributes to action method to indicate the kind of Http request the action method supports. If you do not apply any attribute then it considers GET request by default.
The following figure illustrates HttpGET and HttpPOST action verbs.
The following table lists the usage of http methods:
Http method | Usage |
---|---|
GET | To retrieve the information from the server. Parameters will be appended in the query string. |
POST | To create a new resource. |
PUT | To update an existing resource. |
HEAD | Identical to GET except that server do not return message body. |
OPTIONS | OPTIONS method represents a request for information about the communication options supported by web server. |
DELETE | To delete an existing resource. |
PATCH | To full or partial update the resource. |
Visit W3.org for more information on Http Methods.
The following example shows different action methods supports different ActionVerbs:
You can also apply multiple http verbs using AcceptVerbs attribute. GetAndPostAction method supports both, GET and POST ActionVerbs in the following example:
Points to Remember :
- ActionVerbs are another Action Selectors which selects an action method based on request methods e.g POST, GET, PUT etc.
- Multiple action methods can have same name with different action verbs. Method overloading rules are applicable.
- Mulitple action verbs can be applied to a single action method using AcceptVerbs attribute.
No comments:
Post a Comment