【发布时间】:2020-10-07 19:39:19
【问题描述】:
我有以下控制器:
[Route("blog")]
[Route("{locale:regex(^(de|es|fr)$)}/blog", Order = -1)]
public class BlogController : Controller {
[HttpGet("{id:int}.htm")]
[HttpGet("{slug}/{id:int}.htm")]
public IActionResult Details(string? slug, int id) {
return View();
}
}
现在,如果我尝试生成以下 URL:
- @Url.Action("Details", "Blog", new { id = 1 })
- @Url.Action("详细信息", "博客", 新 { slug = "cat-1", id = 1 })
- @Url.Action("详细信息", "博客", new { id = 1, locale = "fr" })
- @Url.Action("详细信息", "博客", 新 { slug = "cat-1", id = 1, locale = "fr" })
我希望得到以下结果:
- /blog/1.htm
- /blog/cat-1/1.htm
- /fr/blog/1.htm
- /fr/blog/cat-1/1.htm
但是这会返回:
- /blog/1.htm
- /blog/1.htm?slug=cat-1
- /fr/blog/1.htm
- /fr/blog/1.htm?slug=cat-1
我已尝试更改所有路由属性的顺序,但我无法让它返回所需的结果,我将不胜感激。
【问题讨论】:
标签: c# asp.net-core routes asp.net-core-routing