ASP.NET Core 2.1 MVC应用程序具有以下规则:
routes.MapRoute(
name: "blog_list_year_month",
defaults: new {
controller = "Blog",
action = "Index",
year = (int?)null,
month = (int?)null
},
template: "blog/{year?}/{month?}");
对于2018年1月,规则将生成类似blog/2018/1
的网址。
如何表达月份应始终为两位数?即该引擎宁愿生成网址blog/2018/01
?
答案 0 :(得分:0)
您是否已经查看了两个月的正则表达式并将其设置为路线约束?
例如:
new {month = @"(0[1-9]|1[0-2])"}
这应该将您的参数限制为两位数。