【问题标题】:Route thinks there are 2 controllers.Route 认为有 2 个控制器。
【发布时间】:2016-09-29 18:59:28
【问题描述】:

我正在开发一个 mvc 应用程序,并且在解决路由时遇到多个控制器冲突。只有一个控制器,站点中只有一个 dll 有控制器。这是一个很大的dll,这个dll中有很多控制器。其他 MVC 路线工作正常。为什么会这样?

我知道有 2 个同名的控制器应该被命名空间。我知道拥有一个新旧 dll 都会在应用程序中加载并导致冲突,这不是问题。 - Multiple types were found that match the controller named 'Home'

The request for 'Nelson' has found the following matching controllers:
MyWebsite.Areas.Controllers.NelsonController
MyWebsite.Areas.Controllers.NelsonController

[InvalidOperationException: Multiple types were found that match the controller named 'Nelson'. This can happen if the route that services this request ('Nelson/NelsonGridView/{NelsonGVM}') 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 'Nelson' has found the following matching controllers:
MyWebsite.Areas.Controllers.NelsonController
MyWebsite.Areas.Controllers.NelsonController]

//路线

context.MapRoute(
    "Nelson 603 Grid View",
    "Nelson/NelsonGridView/{NelsonGVM}",
    new { controller = this.AreaName, action = "NelsonGridView", NelsonGVM = new NelsonGVM() }
);

示例网址调用:

https://mysite/CR/Nelson/NelsonGridView/

【问题讨论】:

    标签: c# .net asp.net-mvc


    【解决方案1】:

    唯一的可能是您最终可能会在 bin 文件夹中拥有重复的 dll。你有没有机会重命名你的项目命名空间?因为这将触发 VS.NET 生成新程序集,并将旧程序集并排留在 bin 文件夹中。

    请清理 bin 文件夹。重建并尝试它。

    【讨论】:

    • 是的,我就是这么想的。我清理了垃圾箱。但是在此之前和之后都存在一些区域,并且它们都可以正常工作。
    猜你喜欢
    • 2013-03-23
    • 1970-01-01
    • 1970-01-01
    • 2018-07-30
    • 2017-02-14
    • 2017-03-13
    • 1970-01-01
    • 1970-01-01
    • 2011-03-05
    相关资源
    最近更新 更多