| by Achyut Kendre | No comments

What is Controller & Action?

ASP NET MVC 5

In previous article we told you that controller is c part of MVC who is responsible for logic part of the application, in this article we will elaborate more about the controller and action.

What is Controller?

Controller in ASP.NET MVC is just a class located in Controllers folder will have a suffix of Controller in name and will inherit from the built in class called System.Web.MVC.Controller.

It contains set of methods called actions and their will be one to one mapping with user request and action.

What is Action?

Action is public method defined in controller class which contains logic or processing the request. Action method will have the following rules –

  • Action method should be public can not be private or protected.
  • Action Method can not static, abstract or overloaded.
  • Action Method can have the parameters primitive or complex type of parameter.

What is Routing/ Route Engine?

MVC routing in ASP.NET is responsible for mapping incoming browser requests to the specific MVC Controller action. For routing Route Engine Maintains route table and route table contains url patterns called routes. Request URL will be compared with every url pattern from route table, where there is match it will handover the request to specific action of
specific controller.
If there is no match or controller/action not found it will generate not found error.
You can register routes/Url patterns to route table/collection.
URL /Route will be Comparison will be Sequentially.

Basic Working Flow of ASP.NET MVC Application