写了一个Attribute路由Route("Home/{category?}/{subcategory?}/List")想匹配以下规则/Home/C1/S1/List , /Home/C1/List , /Home/List好像只能匹配到第一种情况,可选参数没起作用。 如若匹配以上怎么用一个路由规则搞定?public class HomeController : Controller{ public IActionResult Index() { return View(); } [Route("Home/{category?}/{subcategory?}/List")] public IActionResult List(Category? category = null, SubCategory? subcategory = null) { return Content(category.ToString() + "/" + subcategory.ToString()); } [Route("Home/{code}/Detail")] public IActionResult Detail(string code) { return Content(code); }}public enum Category{ C1, C2, C3, C4}public enum SubCategory{ S1, S2, S3, S4}在stackoverflow的提问:asp.net mvc routing with multiple optional parameters did not work
2 回答
素胚勾勒不出你
TA贡献1827条经验 获得超9个赞
一个路由应该是做不到,使用三个可以
[Route("Home/List")] [Route("Home/{category?}/List")] [Route("Home/{category?}/{subcategory?}/List")]
- 2 回答
- 0 关注
- 1084 浏览
添加回答
举报
0/150
提交
取消