Controllers:-

In previous articles we discussed about the MVC pattern, sample MVC application and its application structure. Now let discuss more about one of the core components of MVC pattern.

Controller is responsible for many operations in asp.net application and major items are listed below

  1. It is responsible responding to user input such as button/hyperlink click, mouse/keyboard operation etc,
  2. It is responsible to making changes to the model in response to user input.
  3. It is responsible to load the relevant view to the user based on the user input

Controller Class

You can create controller class by following the below pattern

  1. Any class need to act as a Controller should be inherited from the Controller class
  2. All the controller class should be placed inside the \Controllers folder
  3. Controller class name should be prefixed with Controller e.g: HomeController, ProductController, etc Minimum controller class should have one action method

Example

ASP.Net Web Form page request cycle

Below diagram explains about the user request is processed based on web form

ASP.Net MVC page request cycle

Below diagram explains about the user request is processed based on MVC