繁体   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