Action Selectors in ASP.NET MVC

action selectors in mvc

Action Selectors in MVC

Action selector is the attribute that can be applied to the action methods. It helps to route engine to select the correct action method to handle a particular request. MVC 5 includes the following action selector attributes:

    1. ActionName
    2. NonAction
    3. ActionVerbs


ActionName attribute allows us to specify a different action name than the method name. Consider the following example.


In the above example, we have applied ActioName("find") attribute to GetById action method. So now, action name is “find” instead of “GetById”. This action method will be invoked on http://localhost/student/find/1 request instead of http://localhost/student/getbyid/1 request.


NonAction selector attribute indicates that a public method of a Controller is not an action method. Use NonAction attribute when you want a public method in a controller but do not want to treat it as an action method.

For example, the GetStudent() the public method cannot be invoked in the same way as the action method in the following example.



I hope you liked this article based on action selectors in mvc. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.


Please enter your comment!
Please enter your name here