MVC(Model-View-Controller) - is a software architecture pattern for designing and developing web application. It divides the web application in 3 segments Model, View and Controller.
ASP.NET MVC is Microsoft's open source web development framework having MVC (Model-View-Controller) architecture which is used for developing MVC based applications. This is the most extensible and customizable framework provided by Microsoft.
Easier development- MVC divides the project into a different segments which then becomes easy for developers
1. Less maintenance cost- It is easy to edit some part of the project which makes project with less maintenance cost
2. Systematic- Projects become more systematic through mvc
3. Auto testing- It provides the way to write unit tests and automate UI manual testing
User request first hits the controller coming from the user. Controller receives this request and decides which model is to be used based on the request. It then passes the model to view which transforms the model and generate view response in order to serve the request and this view is then rendered to the user.
Following steps are involved in the execution of an MVC project
Routing is a pattern matching technique which helps to decide a URL structure and map the URL with the Controller. It matches incoming requests to the URL patterns which are registered in route table. We need to use "UrlRoutingModule" class for it.
Following three segments are important for routing
We have to do setting at two places in Web.config file- by enabling routing in it and in Global.asax file-route table to be created to start event handler.
We need to set following to specify the route
1. To include placeholder in URL pattern
2. To specify a handler either an .aspx file or as controller class
3. To name the route but it is not mandatory
We can add constraints to the route in two ways i.e. by using Regular Expressions or by implementing IRouteConstraint interface.
"RouteConfig.cs" is used to contain the routing configuration. It is initialized on Application_Start event registered in Global.asax.