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中均自动生成。
  • 相关阅读:
    tkinter_战队数据查询系统
    python_tkinter组件
    python_tkinter基本属性
    python_tkinter组件摆放方式
    python_推导式
    python_装饰器
    python_模块1
    python_生成随机验证码
    linux基础_使用指令3
    linux部署django项目流程(全)
  • 原文地址:https://www.cnblogs.com/pengzhen/p/3774504.html
Copyright © 2011-2022 走看看