在这里,我添加了区域,我已经采取了男人和女人两个女人档案(男人和女人)我有HomeController&当我尝试执行视图时将其索引通过错误为
发现多个类型与名为“Home”的控制器匹配。如果为此请求提供服务的路由('{controller} / {action} / {id}')未指定名称空间来搜索与请求匹配的控制器,则会发生这种情况。如果是这种情况,请通过调用带有'namespaces'参数的'MapRoute'方法的重载来注册此路由。
我在RouteConfix.cs中添加了文件
namespace Delete
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "MyNamespace.Home", "MyNamespace2.Home" }
);
}
}
}
WomensAreaRegister.cs
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Women_default",
"Women/{controller}/{action}/{id}",
new {Controller="Department", action = "Index", id = UrlParameter.Optional },
new[] { "MyNamespace.Areas.Admin.Controllers" }
);
}
MensAreaRegister.cs
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Men_default",
"Men/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }, new[] { "MyNamespace2.Areas.Admin.Controllers" }
);
}
请帮助我,我做错了
答案 0 :(得分:0)
在Route.Config中添加它 默认值:new {controller =“Home”,action =“Index”,id =
UrlParameter.Optional },
namespaces: new[] { "ProjectName.Controllers" }
并在Yours Area Controller中添加
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Women_default",
"Women/{controller}/{action}/{id}",
new {Controller="Home", action = "Index", id = UrlParameter.Optional }
);