码迷,mamicode.com
首页 > Web开发 > 详细

如何将MVC AREA中的某一个页设为起始页

时间:2016-07-31 19:25:48      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

Area中AdminAreaRegistration如下:

 1     public class AdminAreaRegistration : AreaRegistration
 2     {
 3         public override string AreaName
 4         {
 5             get
 6             {
 7                 return "Admin";
 8             }
 9         }
10 
11         public override void RegisterArea(AreaRegistrationContext context)
12         {
13             context.MapRoute(
14                 "Admin_default",
15                 "Admin/{controller}/{action}/{id}",
16                 new { controller="Manage", action = "Index", id = UrlParameter.Optional }
17             );
18         }
19     }

Global.asax中如下设置:

技术分享
 1         public static void RegisterRoutes(RouteCollection routes)
 2         {
 3             routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
 4 
 5             routes.MapRoute(
 6                 "Default", // 路由名称
 7                 "{controller}/{action}/{id}", // 带有参数的 URL
 8                 new { controller = "Manage", action = "Index", id = UrlParameter.Optional } // 参数默认值
 9             );
10 
11         }
12 
13         protected void Application_Start()
14         {
15             AreaRegistration.RegisterAllAreas();
16 
17             RegisterGlobalFilters(GlobalFilters.Filters);
18             RegisterRoutes(RouteTable.Routes);
19         }
技术分享

运行时提示

未找到视图“Index”或其母版视图,或没有视图引擎支持搜索的位置。搜索了以下位置: 
~/Views/Manage/Index.aspx
~/Views/Manage/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Manage/Index.cshtml
~/Views/Manage/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml

 

解决方式:

public static void RegisterRoutes(RouteCollection routes)
{
  routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

  routes.MapRoute(
      name: "Default",
      url: "{controller}/{action}/{id}",
      defaults: new { controller = "Home", action = "Login", id = UrlParameter.Optional},
      namespaces:new string[]{"MVCUI.Areas.自己Area的名称.Controllers"}
      ).DataTokens.Add("Area","自己Area的名称");(就是Areas下一级的名称)
}

 

如何将MVC AREA中的某一个页设为起始页

标签:

原文地址:http://www.cnblogs.com/michealm/p/5723570.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!