1. Asp.net mvc url Routing
- IIS determines the request shocould be handled by ASP. NET
- The mvchandler uses icontrollerfactory to obtain an instance of icontroller using the "controller" Route data from the route {controller}/{action}/{ID }.
Public static void registerroutes (routecollection routes) <br/> {<br/> routes. ignoreroute ("{resource }. axd/{* pathinfo} "); </P> <p> routes. maproute (<br/> "default", // route name <br/> "{controller}/{action}/{ID }", // URL with parameters <br/> New {controller = "home", Action = "Index", id = urlparameter. optional} // parameter defaults <br/>); </P> <p >}</P> <p> protected void application_start () <br/>{< br/> arearegistration. registerallareas (); </P> <p> registerroutes (routetable. routes); <br/>}
- The homecontroller is found, and its execute method is invoked
- The homecontroller invokes the index action
- The index action adds some objects to the viewdata dictionary
Public actionresult index () <br/>{< br/> viewdata ["message"] = "Welcome to ASP. net mvc! "; </P> <p> return view (); <br/>}
- ASP. NET renders the response to the browser.
<H2> <% = html. encode (viewdata ["message"]) %> </H2>
2. Controller
Public actionresult index () <br/>{< br/> viewdata. add ("text", "Hello World2"); </P> <p> return view (); <br/>}
<H2> <% = viewdata ["text"] %> </H2>
Public actionresult index () <br/>{< br/> return view (object) "Hello world3"); <br/>}
<H2> <% = model %> I'm strongrong typed in a layout. </H2>