生活随笔
收集整理的这篇文章主要介绍了
MVC Area Usage
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
ASP.NET MVC Area操作 新建 Area:右键 -> Add –> Area 继承 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 });}
} (附:一般的路由映射) 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称之为子站 的原因。 在 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);
} 以上所有步骤在VS2013或VS2012中均自动生成。
转载于:https://www.cnblogs.com/pengzhen/p/3774504.html
总结
以上是生活随笔 为你收集整理的MVC Area Usage 的全部内容,希望文章能够帮你解决所遇到的问题。
如果觉得生活随笔 网站内容还不错,欢迎将生活随笔 推荐给好友。