我在global.asax中定义了以下路由:
routes.MapRoute(
"Agreements2", // Route name
"Agreements2/{action}/{id}", // URL with parameters
new { controller = "Agreements", action = "AgreementSummery", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Agreements", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Agreements", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
后一条路线运行良好,但我不明白为什么第一条路线不起作用。
协议控制方的AgreementSummery方法定义为:
[HttpGet]
public ActionResult AgreementSummery(int? id)
{
AgreementsModel model = new AgreementsModel();
model.SelectedAgreementID = id.Value;
return View(model);
}
答案 0 :(得分:1)
id未定义为可选,它被定义为可空。如果为其分配了值
,则为可选项public ActionResult AgreementSummery(int? id = null)