[英]MVC4 areas problems(is already in the route collection)
名为“ Home_default2”的路由已在路由集合中。 路由名称必须唯一。
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
AreaRegistration.RegisterAllAreas();
routes.MapRoute(
name: "Default",
url: "area/{controller}/{action}/{id}",
defaults: new {area="Home_Default", controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
public override string AreaName
{
get
{
return "Home";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Home_default2",
"Home/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
}
自动生成的代码有问题,我做错了什么?
要解决此问题,只需删除bin文件夹中的所有.dll files
,然后重新构建解决方案。 这应该为您解决问题。
问题是重复的`AreaRegistration.RegisterAllAreas();。 在途中和在global.asax上
所以只需要这个:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
将Home_Default更改为Home。
就我而言,我创建了一个区域,并在Route.config中添加了这一行。
AreaRegistration.RegisterAllAreas();
但是该语句已经存在于global.asax的Application_start中。 因此得到了错误。
因此将其从route.config中删除。 我没有为其更改任何路线名称。 一个路由名称是默认名称(在RouteConfig文件中),另一个是areaname_default(在AreaRegistration.cs文件中)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.