ASP.NET MVC Life Cycle (How ASP.NET MVC works)

Asp.Net MVC Life Cycle


ASP.NET MVC Life Cycle :
       The Asp.Net MVC Life Cycle follows the following steps.They are :
  1. Browser request happens with a specific URL.For e.g."http://www.abc.com/home/index" 
  2. The specified URL will then get pass via Application_Start( ) method  of Global.asax file.From the requested URL it will parse the Controller,Action & Id.In the above requested URL , "home" is the controller,"Index" is the action and here Id is not specified so it is empty.
  3. MVC now finds the "homeController" in  the "Controllers" directive.A controller class contains different action methods. There can be more than one action methods.But MVC only invoke the parsed action method which is available after parsing specified URL(In our case it is "Index()" action).
  4. After invoking the action method it will return "ActionResult".The action result can be plain string (Non-ViewResult) or a View (ViewResult).If it returns plain string then it will print the string in the browser.If  it returns View() then it will search the particular page in the "Views" directory.If view page is found then by the help of View Engine the Html Helpers or the view page elements are converted/rendered to the corresponding HTML format and presented in the browser. In our case the view/page which is returned by calling the Index() action method will be present in the location : "/Views/home/Index.cshtml".

No comments:

Post a Comment