zoukankan      html  css  js  c++  java
  • MVC Area Usage

    ASP.NET MVC Area操作

    1. 新建 Area:右键 -> Add –> Area
    2. 继承 AreaRegistration,重写AreaName属性与RegisterArea方法
      public class BookStudyAreaRegistration : AreaRegistration
      {
          public override string AreaName
          {
              get
              {
                  return "BookStudy";
              }
          }
      
          public override void RegisterArea(AreaRegistrationContext context)
          {
              context.MapRoute(
                  "BookStudy_default",
                  
      "BookStudy/{controller}/{action}/{id}"
      ,
                  new { action = "Index", id = UrlParameter.Optional }
              );
          }
      }
    3. (附:一般的路由映射)
      public class RouteConfig
      {
          public static void RegisterRoutes(RouteCollection routes)
          {
              routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
              routes.MapRoute(
                  name: "Default",
                  url: 
      "{controller}/{action}/{id}"
      ,
                  defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                  namespaces: new string[] { "MyKB.Controllers" }
              );
          }
      }
      请注意与RegisterArea的url参数进行对比,只多了一个“BookStudy”,即AreaName。——这也是将Area称之为子站的原因。
    4. 在 Global 中注册此 Area
      protected void Application_Start()
      {
          AreaRegistration.RegisterAllAreas();
      
          WebApiConfig.Register(GlobalConfiguration.Configuration); // here
          FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
          RouteConfig.RegisterRoutes(RouteTable.Routes);
          BundleConfig.RegisterBundles(BundleTable.Bundles);
      }
    5. 以上所有步骤在VS2013或VS2012中均自动生成。
  • 相关阅读:
    必须掌握的八个DOS命令
    实况足球8 功略简解
    开始→运行→命令集锦
    必须掌握的八个DOS命令
    对称加密算法之DES算法
    让你的Linux像黑客帝国的画面一样炫酷
    古典密码之凯撒密码and换位密码
    用eclipse写jsp报以下错误
    mysql安装后,过一段时间,在命令行无法启动
    sql 日期函数
  • 原文地址:https://www.cnblogs.com/pengzhen/p/3774504.html
Copyright © 2011-2022 走看看