Asp.net MVC getting started with this framework

Source: Internet
Author: User
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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.