标签:
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下一级的名称)
}
标签:
原文地址:http://www.cnblogs.com/michealm/p/5723570.html