MVC Area Usage

Source: Internet
Author: User

ASP. NET MVC Area operations
  1. New Area: Right-click add–> area
  2. Inherit Arearegistration, override AreaName property and Registerarea method
     Public classbookstudyarearegistration: arearegistration{ Public Override string areaname {Get        {            return "Bookstudy"; }    }     Public Override void Registerarea(AreaRegistrationContext context) {context. MapRoute ("Bookstudy_default",            
    "bookstudy/{controller}/{action}/{id}"
    ,             New " Index ", id = urlparameter.optional}        );}    }
  3. (Attached: generic route map)
     public  class  public   Static  void   registerroutes    (RouteCollection routes) {routes. Ignoreroute (  " {resource        }.axd/{*pathinfo}   " ); Routes. MapRoute (name:   " defaul T   " url:   
    " {controller}/{action}/{id} "
    ,             New " Home " " Index ", id = urlparameter.optional},            newstring"  Mykb.controllers"  }        );}    }
    Please note that withRegisterareaThe URL parameter to compare, only a "bookstudy", that is, areaname. -This is also called the areaSub-stationThe reason.
  4. Register this area in Global
    protected void Application_Start () {    arearegistration.registerallareas ();     //  Here     filterconfig.registerglobalfilters (globalfilters.filters);    Routeconfig.registerroutes (routetable.routes);    Bundleconfig.registerbundles (bundletable.bundles);}
  5. All of the above steps are automatically generated in VS2013 or VS2012.

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.