a.Model represents data and business logic . It maintains the data of the application.

Ex .:

public class Employee{public string EmpSal { get; set; }}

Model objects retrieve and store properties in database.

b.View is user interface. It display the data to user using model and also modify the data.

c. Controller Handles User Request.

Employee controller will handle all user inputs from employee view and update the database using Employee model and same is used by view to display data to user.

As per above figure, when user requests url,it goes to the controller. Controller decides which action should be executed. It picks up the relevant view and send data to user.

If we go in deeper details in ASP.NET MVC, when the user sends a request to IIS, it validates the requested file extension & creates an application domain where the app can run. Later HttpApplication object is created once after all the HTTP object such as HttpContext, HttpRequest and HttpResponse are created. Then the request is processed by the two prominent pillars called HttpModule and HttpHandlers.

Areas in MVC : Areas are useful for managing web applications. Each Area has its own controller, Model & view.

Each area has its own AreaRegistration.cs file similar to Route.config file.

All areas are registered in Application Start event of Global.asax file :

AreaRegistration.RegisterAllAreas();

Route.Config File :

Route.Config file is entry point of web application which decides how url are mapped to controller and its appropriate actions. Controller is responsible for generating the response and sent data back to the browser(user).Each controller can handle multiple requests.

When the user requests for url, Application_Start event will get called & it will call RegisterRoutes method.It will send the collection of routes as parameter.Each route references a handler which will handle the request.

If it finds correct match for request ,it will create RequestContext object and send request to MVCHandler. As soon as match is found, scanning of RouteTable Process stops.

Depending on requested url, it will call controller’s ActionInvoker method which creates list of parameters of url request and list will be passed to controller action method to call InvokeAction method to execute the action. Finally it will send response to user.

MVC Handler :

This class is responsible for generating response for request being processed.

It receives the information about the request from RequestContext object and passed to constructor, in implementation of GetHttpHandler() method in MVCRouteHandler class.

ControllerActionInvoker that creates list of parameters.The parametets will be passed to respective

Controller AactionMethod gets executed.

Action Result

As we are clear that, once the ActionMethod executes our logic we will return an ActionResult, based on the type of Result it returns, View generates accordingly.

Before that we do have some ActionFilter methods which is invoked based on ActionMethod’s life cycle. Some methods are such as OnActionExecuting, OnActionExecuted etc.

Let us see some of the ActionResult types as well,

ViewResult : Returns a view (html type page)

RedirectResult : Redirects to another action method

ContentResult : Returns Content (user defined)

JsonResult : Returns a serialized JSON data

If you do not want any specific method should not accessible through public URL, you can mark that method with [NonAction] attribute.

Rendering View :

The final and tangible step in MVC life cycle is rendering the View, where the user can see what he requested and get as a response. The ViewResult one of the ActionResult generates the appropriate View to the user, by parsing the Razor syntax (cshtml) and server side codes into HTML page to the Client.

ViewResult implements the IViewEngine Interface and has some view manipulating methods such as: