【发布时间】:2017-07-05 02:02:06
【问题描述】:
有3个属性路由
[Route("{foo}_{bar}_{fee}_o_p")]
ActionResult SelectFee[Route("{foo}_{bar}_{fee}_{fii}_o_p")] ActionResult SelectFii[Route("{foo}_{bar}_{fee}_{fii}_{fum}_o_p")] ActionResult SelectFum
前 2 个按预期工作。 但是最后一个出现了一个模棱两可的反射错误。
如果我将它们中的 2 个移到另一个区域/控制器也很奇怪,它们也会出现模棱两可的错误
如果我更新到
[Route("Select/{foo}_{bar}_{fee}_{fii}_{fum}_o_p")]ActionResult SelectFum
它有效...
路线是 public ActionResult SelectFee(string foo, string bar, string fee) public ActionResult SelectFii(string foo, string bar, string fee, string fii) public ActionResult SelectFum(string foo, string bar, string fee, string fii, string fum)
Elmah 的确切错误
System.Reflection.AmbiguousMatchException:当前请求在以下操作方法之间不明确:
RexProject.Controllers.ShopController
类型上的 System.Web.Mvc.ActionResult SelectedFee(System.String, System.String, System.String)
RexProject.Controllers.ShopController
类型上的 System.Web.Mvc.ActionResult SelectFii(System.String, System.String, System.String, System.String)
RexProject.Controllers.ShopController 类型上的 System.Web.Mvc.ActionResult SelectFum(System.String, System.String, System.String, System.String, System.String)
任何输入都会有所帮助! 谢谢!
解决方案(或解决方法)
去掉了Attribute路由,放到RouteConfig的RegisterRoutes Method里面,Longest First,按预期工作。
【问题讨论】:
-
所有 3 条路由都是相同的 - 它们指定 url 仅包含一个段。
-
显示您的完整操作签名。如果最后一个参数可以为空,那么这就是您收到该错误的原因
标签: asp.net-mvc asp.net-mvc-5 asp.net-mvc-routing