【发布时间】:2020-06-17 02:57:15
【问题描述】:
我尝试在我的项目中实现 Phil's Areas Demo
http://haacked.com/archive/2008/11/04/areas-in-aspnetmvc.aspx.
我在现有 MVC 项目中附加了 Areas/Blog 结构,但在我的项目中出现以下错误。
控制器名称Home在以下类型之间有歧义:
WebMVC.Controllers.HomeController
WebMVC.Areas.Blogs.Controllers.HomeController
这就是我的Global.asax 的样子。
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapAreas("{controller}/{action}/{id}",
"WebMVC.Areas.Blogs",
new[] { "Blogs", "Forums" });
routes.MapRootArea("{controller}/{action}/{id}",
"WebMVC",
new { controller = "Home", action = "Index", id = "" });
//routes.MapRoute(
// "Default", // Route name
// "{controller}/{action}/{id}",// URL with parameters
// new { controller = "Home", action = "Index", id = "" }
// // Parameter defaults
//);
}
protected void Application_Start()
{
String assemblyName = Assembly.GetExecutingAssembly().CodeBase;
String path = new Uri(assemblyName).LocalPath;
Directory.SetCurrentDirectory(Path.GetDirectoryName(path));
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new AreaViewEngine());
RegisterRoutes(RouteTable.Routes);
// RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
}
如果我从routes.MapAreas 中删除/Areas/Blogs,它会查看根的索引。
【问题讨论】:
标签: asp.net-mvc