我希望能够以两种不同的方式访问同一页面:
首先,使用参数显示一些特定信息。
routes.MapRoute(
"About",
"About/{id}",
new { controller = "About", action = "Index" }
);
其次,没有参数,以显示一般事物。
routes.MapRoute(
"About",
"About",
new { controller = "About", action = "Index" }
);
如何建立接受这两种选择的路线?
答案 0 :(得分:2)
routes.MapRoute(
"About",
"About/{id}",
new { controller = "About", action = "Index", id = UrlParameter.Optional }
);
然后:
public ActionResult Index(string id)
{
// if id = null => /About was requested
// if id != null => /About/abc was requested
...
}