簡體   English   中英

如何在不導致歧義的情況下為索引設置asp.net mvc屬性路由?

[英]how do i set asp.net mvc attribute routing for the index without leading to ambiguity?

Asp.net mvc 5.1引入了以下重大更改( http://www.asp.net/mvc/overview/releases/mvc51-release-notes ):

現在,屬性路由匹配中的歧義將報告錯誤,而不是選擇第一個匹配。

我有以下幾點:

SomeController:

[Route("{sort=data}/{page:int=1}/{type:values(completo|parcial)=completo}", Name = "Default"), OutputCache(Duration = 5)]
public ActionResult Index(string sort, int page, string type)

AccountController:

[AllowAnonymous, Route("entrar")]
public ActionResult Login(string returnUrl)

當我嘗試訪問/ entrar時,會導致與Index控制器產生歧義。

有想法該怎么解決這個嗎?

謝謝。

固定方式如下:

[Route("{sort:values(mais-votados-7|comentado-por-ultimo|data)=data}/{page:int=1}/{type:values(completo|parcial)=completo}", Name = "Default")]
[OutputCache(Duration = 5)]
public ActionResult Index(string sort, int page, string type)

通過設置{sort}的允許值,/ entrar不再與此路由匹配。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM