我无法弄清楚这一点。
如何解决问题?
AdminAreaReistration cs
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"CMSAdmin_default",
"CMSAdmin/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
RouteConfig
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Default", action = "Index", id = UrlParameter.Optional }
);
}
答案 0 :(得分:1)
根据错误图像,您可以在将区域声明为RegisterArea
时使用不同的命名空间,以避免在默认路由和区域路由之间发生命名冲突:
AdminAreaRegistration.cs
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"CMSAdmin_default",
"CMSAdmin/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional },
new[] { "cms.site.Areas.CMSAdmin.Controllers" } // Insert area namespace here
);
}
RouteConfig.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Default", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "cms.site.Controllers" } // Insert project namespace here
);
}
Multiple types were found that match the controller name
错误导致的可能原因:
1)使用具有不同区域的相同控制器名称(这可能是您当前的问题),
2)重命名项目命名空间/程序集名称(删除/ bin目录中的旧项目名称DLL文件,然后再次清理并重建),
3)具有相同名称但不同版本的引用之间的冲突(删除旧引用然后重构)。
参考文献:
Multiple types were found that match the controller named 'Home'
Having issue with multiple controllers of the same name in my project