Sure. The page life cycle of MVC is the sequence of events that occur when an HTTP request is handled by an MVC application. The page life cycle is divided into the following phases:
Routing: The routing phase is responsible for matching the incoming HTTP request to a controller action.
Controller: The controller phase is responsible for handling the HTTP request and returning a response.
View: The view phase is responsible for rendering the response to the browser.
Unloading: The unloading phase is responsible for cleaning up any resources that were used during the page life cycle.
The following is a brief description of each phase of the MVC page life cycle:
Routing: The routing phase is responsible for matching the incoming HTTP request to a controller action. The routing engine uses a set of rules to match the request to a controller action. The rules can be configured in the web.config file or in code.
Controller: The controller phase is responsible for handling the HTTP request and returning a response. The controller action receives the HTTP request and performs the necessary tasks to generate the response. The response can be a view, a redirect, or some other type of response.
View: The view phase is responsible for rendering the response to the browser. The view engine uses a template to render the response. The template can be a Razor template or a web form template.
Unloading: The unloading phase is responsible for cleaning up any resources that were used during the page life cycle. The unloading phase is responsible for releasing memory, closing database connections, and other tasks.
The MVC page life cycle is a powerful tool that can be used to create efficient and scalable web applications. The page life cycle is well-defined and easy to understand, which makes it easy to debug and maintain MVC applications.
Step 1 Fill route: - MVC requests are mapped to route tables which in turn specify which controller and action to be invoked. So if the request is the first request the first thing is to fill the routing table with routes collection. This filling of the routing table happens in the global.asax file.
Step 2 Fetch route:- Depending on the URL sent "UrlRoutingModule" searches the routing table to create "RouteData" object which has the details of which controller and action to invoke.
Step 3 Request context created: - The "RouteData" object is used to create the "RequestContext" object.
Step 4 Controller instance created: - This request object is sent to "MvcHandler" instance to create the controller class instance. Once the controller class object is created it calls the "Execute" method of the controller class.
Creating Response object: - This phase has two steps executing the action and finally sending the response as a result of the view.
Step 5 Execute Action: - The "ControllerActionInvoker" determines which action to executed and executes the action.
Step 6 Result sent: - The action method executes and creates the type of result which can be a view result, file result, JSON result, etc.
Liked By
Write Answer
Can you explain the page life cycle of MVC?
Join MindStick Community
You have need login or register for voting of answers or question.
Aryan Kumar
18-Jun-2023Sure. The page life cycle of MVC is the sequence of events that occur when an HTTP request is handled by an MVC application. The page life cycle is divided into the following phases:
The following is a brief description of each phase of the MVC page life cycle:
The MVC page life cycle is a powerful tool that can be used to create efficient and scalable web applications. The page life cycle is well-defined and easy to understand, which makes it easy to debug and maintain MVC applications.
Anonymous User
27-Jun-2019The page life cycle of MVC
Step 1 Fill route: - MVC requests are mapped to route tables which in turn specify which controller and action to be invoked. So if the request is the first request the first thing is to fill the routing table with routes collection. This filling of the routing table happens in the global.asax file.
Step 2 Fetch route:- Depending on the URL sent "UrlRoutingModule" searches the routing table to create "RouteData" object which has the details of which controller and action to invoke.
Step 3 Request context created: - The "RouteData" object is used to create the "RequestContext" object.
Step 4 Controller instance created: - This request object is sent to "MvcHandler" instance to create the controller class instance. Once the controller class object is created it calls the "Execute" method of the controller class.
Creating Response object: - This phase has two steps executing the action and finally sending the response as a result of the view.
Step 5 Execute Action: - The "ControllerActionInvoker" determines which action to executed and executes the action.
Step 6 Result sent: - The action method executes and creates the type of result which can be a view result, file result, JSON result, etc.