It is important to understand the request lifecycle in ASP.Net MVC before we proceed with other tutorials. In this article I will briefly discuss to you how the ASP.Net MVC handles the request.
When we make http request in our MVC application it will look for the registered routes in URL Routing Module to determine which controller should handle the request.
You can check the registered routes in App_Start folder then open the RouteConfig.cs
Look at the value of url in routes.MapRoute and compare it to the url that we have in our browser.
In the above image the controller is the Books, then the action is Edit and the id is 1.
When we access the above url, it will first look at the registered routes to determine which controller will handle the request. After determining the controller it will initialize the controller and a module called Action Invoker will find what action should will be executed for the request.
If you look at the code in BooksController, you will find the Edit method.
After executing the action, if the result is a view, the view engine will find the necessary view in Views Folder. In this case it will look for Views -> Books -> Edit.cshtml then it will render the view for the user.
Related Articles
- Library Management using ASP.Net MVC (Part 1) Books CRUD Function
- Library Management using ASP.Net MVC (Part 3) Adding the Customers
- Library Management using ASP.Net MVC (Part 4) Entity Framework Relationship and Navigation Properties
- Library Management using ASP.Net MVC (Part 5) Eager Loading and Projection
- Library Management using ASP.Net MVC (Part 6) Borrowing and returning a book