当前请求是模糊的MVC属性路由

时间:2017-02-16 05:38:47

标签: asp.net-mvc asp.net-mvc-5 asp.net-mvc-routing

有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个移到另一个区域/控制器,同样也会出现模糊错误,这也很奇怪 如果我更新到 [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:当前请求在以下操作方法之间不明确:
System.Web.Mvc.ActionResult类型为RexProject.Controllers.ShopController的SelectedFee(System.String,System.String,System.String)
System.Web.Mvc.ActionResult在RexProject.Controllers.ShopController类型上选择Fii(System.String,System.String,System.String,System.String) System.Web.Mvc.ActionResult类型RexProject.Controllers.ShopController上的SelectFum(System.String,System.String,System.String,System.String,System.String)

任何输入都会有所帮助! 谢谢!

解决方案(或解决方法)
删除了属性路由,并将它们放在RouteConfig的RegisterRoutes方法中,Longest First,它们按预期工作。

1 个答案:

答案 0 :(得分:0)

如果这是标准的get,则不需要自定义路由,绑定将从查询字符串自动完成,看起来你只是想改变url格式而且我不确定你从中获得了什么它

public ActionResult SelectFum(string foo = null, string bar = null, string fee = null, string fii = null, string fum = null) 
{
   //your code
}
相关问题