找到了多个与名为"Account"的控制器匹配的类型.MVC 4和使用RouteConfig.CS [英] Multiple types were found that match the controller named 'Account'. MVC 4 & using RouteConfig.CS
问题描述
我目前在同一文件夹中有2个项目.主要
I currently have 2 projects in same folder. Main
- Project1
- Project2
找到了多种与名为 Account 的控制器匹配的类型.如果为该请求('{controller}/{action}/{id}')
提供服务的路由未指定名称空间来搜索与该请求匹配的控制器,则会发生这种情况.如果是这种情况,请通过调用带有 namespaces
参数的 MapRoute
方法的重载来注册此路由.
Multiple types were found that match the controller named Account. This can happen if the route that services this request ('{controller}/{action}/{id}')
does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the MapRoute
method that takes a namespaces
parameter.
帐户
的请求已找到以下匹配的控制器:
The request for Account
has found the following matching controllers:
Project1.Controllers.AccountController
Project1.Controllers.AccountController
Project2.Controllers.AccountController
Project2.Controllers.AccountController
我使用Foundation 4.谢谢前进
I using Foundation 4. Thanks advance
推荐答案
您需要使用带有此签名的版本
you need to use the version with this signature
public static Route MapRoute(
this RouteCollection routes,
string name,
string url,
Object defaults,
string[] namespaces )
要使其工作,只需设置两条几乎完全相同的路由-一个路由,其中包括名称空间参数的project1,然后包含第二个相同的版本,但在名称空间参数中使用project2.也就是说,如果可以的话,使用不同的名称通常不会造成混淆.
To make it work just set up two almost identical routes - one which includes the project1 for the namespaces parameter and then a second identical version but use project2 in the namespaces parameter. That said, it would generally be less confusing, to use different names if you can...
routes.MapRoute(
name: "Default_Project1",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional,
namespaces: new string[] { "Project1" } }
);
routes.MapRoute(
name: "Default_Project2",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional,
namespaces: new string[] { "Project2" }
);
这篇关于找到了多个与名为"Account"的控制器匹配的类型.MVC 4和使用RouteConfig.CS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!