C# 属性路由抛出一个";找到多个控制器类型";错误

C# 属性路由抛出一个";找到多个控制器类型";错误,c#,asp.net-mvc,C#,Asp.net Mvc,我只是在使用属性路由,但确实无法使用某些路由 这是我的项目控制器.cs路由属性 [RouteArea("Admin")] [Route("Projects/{action}/{id?}")] public class ProjectsController : Controller [RouteArea("Admin")] [RoutePrefix("Projects")] [Route("Representatives/{action}/{id?}")] public class Repres

我只是在使用属性路由,但确实无法使用某些路由

这是我的项目控制器.cs路由属性

[RouteArea("Admin")]
[Route("Projects/{action}/{id?}")]
public class ProjectsController : Controller
[RouteArea("Admin")]
[RoutePrefix("Projects")]
[Route("Representatives/{action}/{id?}")]
public class RepresentativesController : Controller
这是我的RepresentativeController.cs路由属性

[RouteArea("Admin")]
[Route("Projects/{action}/{id?}")]
public class ProjectsController : Controller
[RouteArea("Admin")]
[RoutePrefix("Projects")]
[Route("Representatives/{action}/{id?}")]
public class RepresentativesController : Controller
这是文件夹结构(虽然不需要):

例如,我无法浏览此Url

/Admin/Projects/Representatives/Index
因为我经常会遇到这样的错误:

Multiple controller types were found that match the URL. This can happen if attribute routes on multiple controllers match the requested URL.

The request has found the following matching controller types: 
FasecItaliaLabMVC.Areas.Admin.Controllers.ProjectsController
FasecItaliaLabMVC.Areas.Admin.Controllers.RepresentativesController

如何解决此问题?

修改路线,可能的选项:

  • [Route(“Projects/{action}/{id?}”)中删除
    {id?}
    ,因为当前
    {id?}
    索引匹配
  • 扩展路径,例如
    [route(“Projects/Main/{action}/{id?}”)]
  • 删除路由前缀
    [RoutePrefix(“项目”)]

  • 很难说单个解决方案,这取决于您的控制器。

    我忘了提到项目控制器没有名为“代表”的操作。选项1仍然有效吗?尝试一下,它应该是有效的解决方案。它是有效的解决方案。。。我想说的是,我不应该得到错误,因为ProjectsController没有名为Representations的操作,或者我错了吗?首先,它会找到有效路由,如果找到有效路由,它会查找控制器。在您的情况下,会找到两个有效的路由并抛出错误,因为不清楚在哪里寻找操作。行动是否存在并不重要。