ASP.NET MVC4添加区域视图 找到多个与名为“home”的控制器匹配的类型

ASP.NET MVC4添加区域视图 找到多个与名为“home”的控制器匹配的类型

今天在项目中遇到一个问题,在MVC下想建立一个区域的后台Boss视图,出现了"找到多个与名为“home”的控制器匹配的类型"的问题,希望下面的解决方案能够帮助到大家

ASP.NET MVC4添加区域视图 找到多个与名为“home”的控制器匹配的类型

这是网站的整体结构,在Areas区域下有一个Boss的管理区域,解决问题只需要将最外层的路由和Boss下的路由设置命名空间就可以了.

这是最外层的路由设置:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing; namespace QNJY.Web
{
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 = "Default", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "QNJY.Web.Controllers" }
);
}
}
}

这是Boss下的路由(BossAreaRegistration.cs)配置:

 using System.Web.Mvc;

 namespace QNJY.Web.Areas.Boss
{
public class BossAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Boss";
}
} public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Boss_default",
"Boss/{controller}/{action}/{id}",
new { controller = "Login", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "QNJY.Web.Areas.Boss.Controllers" }
);
}
}
}
这个是重点:namespaces: new string[] { "QNJY.Web.Areas.Boss.Controllers" }
上一篇:Unity CombineChildren和MeshCombineUtility


下一篇:WPF:窗体置顶