Action Selectores

Last modified on May 08th, 2020 by DigitalIndiaInfo Team.


Action Selectors

Action selector is the attribute that can be applied to the action methods. It helps routing 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

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

Example: ActionName

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

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

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

Points to Remember :


References :

  • www.tutorial.digitalindiainfo.com