ADOU-V

导航

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

 

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

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

这是最外层的路由设置:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.Mvc;
 6 using System.Web.Routing;
 7 
 8 namespace QNJY.Web
 9 {
10     public class RouteConfig
11     {
12         public static void RegisterRoutes(RouteCollection routes)
13         {
14             routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
15 
16             routes.MapRoute(
17                 name: "Default",
18                 url: "{controller}/{action}/{id}",
19                 defaults: new { controller = "Default", action = "Index", id = UrlParameter.Optional },
20                 namespaces: new string[] { "QNJY.Web.Controllers" }
21             );
22         }
23     }
24 }

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

 1 using System.Web.Mvc;
 2 
 3 namespace QNJY.Web.Areas.Boss
 4 {
 5     public class BossAreaRegistration : AreaRegistration 
 6     {
 7         public override string AreaName 
 8         {
 9             get 
10             {
11                 return "Boss";
12             }
13         }
14 
15         public override void RegisterArea(AreaRegistrationContext context) 
16         {
17             context.MapRoute(
18                 "Boss_default",
19                 "Boss/{controller}/{action}/{id}",
20                 new { controller = "Login", action = "Index", id = UrlParameter.Optional },
21                 namespaces: new string[] { "QNJY.Web.Areas.Boss.Controllers" }
22             );
23         }
24     }
25 }
这个是重点:namespaces: new string[] { "QNJY.Web.Areas.Boss.Controllers" }

 

posted on 2017-05-10 02:08  a-dou  阅读(268)  评论(0编辑  收藏  举报