Javatpoint Logo
Javatpoint Logo

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:

  1. ActionName
  2. ActionVerbs


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:

// MusicStoreController.cs

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.

// store.cshtml


The following output is produced when action is called with different name "store".

ASP Action 1


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.

  • HttpPost
  • HttpGet
  • HttpPut
  • HttpDelete
  • HttpOptions
  • HttpPatch

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:

// MusicStoreController.cs

Following is the Index file for MusicStoreController.

// index.cshtml


It produces the following output, when the index action is called.

ASP Action 2

It produces the error message, when we make a get request for the store action method.

ASP Action 3

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA