我注册了一条路线:
routes.MapRoute(
"Journals",
"Journals/{year}/{month}/{id}",
new {
controller = "Journals",
action = "Get",
year = UrlParameter.Optional,
month = UrlParameter.Optional,
id = UrlParameter.Optional
}
);
行动:
public ActionResult Get(int? year, int? month, int? id)
稍后查看(只是为了检查):
@Url.Action("Get", "Journals")
@Url.Action("Get", "Journals", new { year = 2013 })
@Url.Action("Get", "Journals", new { year = 2013, month = 4 })
@Url.Action("Get", "Journals", new { year = 2013, month = 4, id = 1 })
结果是:
/Journals
/Journals
/Journals/2013/4
/Journals/2013/4/1
所以第二个 URL 错过了参数。怎么了?