当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - how do i set asp.net mvc attribute routing for the index without leading to ambiguity?

问题描述:

Asp.net mvc 5.1 introduced the following breaking change (http://www.asp.net/mvc/overview/releases/mvc51-release-notes):

Ambiguities in attribute routing matches will now report an error rather than choosing the first match.

I have the following:

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)

When i try to acess /entrar it leads to ambiguity with the Index controller.

Any ideas on how to fix this?

Thank you.

网友答案:

Fixed it this way:

[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)

By setting the allowed values of {sort}, /entrar does not match this route anymore.

分享给朋友:
您可能感兴趣的文章:
随机阅读: