如何解决找到与命名控制器匹配的多个类型 [英] how sloved Multiple types were found that match the controller named

查看:76
本文介绍了如何解决找到与命名控制器匹配的多个类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了这个错误

找到了多个匹配名为Home的控制器的类型。如果为此请求提供服务的路由('{Controller} / {action} / {id}')未指定名称空间来搜索与请求匹配的控制器,则会发生这种情况。如果是这种情况,请通过调用带有'namespaces'参数的'MapRoute'方法的重载来注册此路由。



'Home'的请求具有找到了以下匹配的控制器:

Web.Areas.BaseAdmin.Controllers.HomeController

Web.Controllers.HomeController

iam see this error
Multiple types were found that match the controller named 'Home'. 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 'Home' has found the following matching controllers:
Web.Areas.BaseAdmin.Controllers.HomeController
Web.Controllers.HomeController

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 }
          );

         routes.MapRoute(
              name: "baseadmin",
           url: "BaseAdmin/Home/{action}/{id}",
              defaults: new
              {
                  controller = "BaseAdmin/Home",
                  action = "Index",
                  issueId = UrlParameter.Optional,
                  projectId = UrlParameter.Optional
              }
          );
      }
  }

推荐答案

you can mention the namespace in the route config as explained below:

 routes.MapRoute(
              name: "Default",
              url: "{Controller}/{action}/{id}",
              defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: Web.Controllers
          );

         routes.MapRoute(
              name: "baseadmin",
           url: "BaseAdmin/Home/{action}/{id}",
              defaults: new
              {
                  controller = "BaseAdmin/Home",
                  action = "Index",
                  issueId = UrlParameter.Optional,
                  projectId = UrlParameter.Optional
              },
           namespaces:Web.Areas.BaseAdmin.Controllers
          );



这篇关于如何解决找到与命名控制器匹配的多个类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆