ASP.NET MVC Action Selectors
Action selectors are attributes that are applied on action methods of a controller. It is used to select correct action method to call as per the request. MVC provides the following action selector attributes:
This attribute allows us to specify a different name for the action method. It is useful when we want to call action by different name.
Here, we are using ActionName attribute to apply different name for the index action method. The controller code looks like this:
Now, we need to create a view in the MusicStore folder as same as the ActionName. So, we have created a store.cshtml file that has following code.
The following output is produced when action is called with different name "store".
ASP.NET MVC provides action verbs that are applied on the action methods and works for HttpRequest methods. There are various ActionVerbs and listed below.
ActionVerbs are name of the http requests that a controller handle. We can use it for selection among the action methods.
In the following example, we are trying to access an index action by get request, which is accessible only for httpPost request. The controller code looks like this:
Following is the Index file for MusicStoreController.
It produces the following output, when the index action is called.
It produces the error message, when we make a get request for the store action method.