2017-02-16 32 views
1

有3級屬性的路由目前的要求是不明確的MVC屬性路線

[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:當前請求在以下操作方法之間不明確:
System.Web.Mvc.ActionResult類型爲RexProject.Controllers.ShopController的SelectedFee(System.String,System.String,System.String)
System.Web.Mvc.ActionResult在類型RexProject.Controllers.ShopController上的SelectFii(System.String,System.String,System.String,System.String)
System.Web.Mvc.ActionResult SelectFum(System.String,System。字符串,System.String,System.String,System.String)類型RexProject.Controllers.ShopController

任何輸入將有所幫助! 謝謝!

解決方案(或變通方法)
刪除了屬性路由,並將它們放置在RouteConfig的RegisterRoutes方法中,Longest First,它們按預期工作。

+0

所有3條路徑都是相同的 - 它們指定url只包含一個段。 –

+0

顯示您的完整操作簽名。如果最後一個參數是可以爲空的,那就是你得到那個錯誤的原因 –

回答

0

如果這是一個標準的get,那麼就不需要自定義路由,綁定將自動從querystring中完成,好像你只是想改變url格式,我不確定你獲得了什麼從中。

public ActionResult SelectFum(string foo = null, string bar = null, string fee = null, string fii = null, string fum = null) 
{ 
    //your code 
} 
+0

但是這對SEO沒有幫助 – juanvan