Asp.net mvc 2 为同一页面创建两个路由选项(MVC)
我希望能够以两种不同的方式访问同一页面: 首先,使用参数来显示一些特定信息Asp.net mvc 2 为同一页面创建两个路由选项(MVC),asp.net-mvc-2,routes,Asp.net Mvc 2,Routes,我希望能够以两种不同的方式访问同一页面: 首先,使用参数来显示一些特定信息 routes.MapRoute( "About", "About/{id}", new { controller = "About", action = "Index" } ); 第二,无参数,显示一般事物 routes.MapRoute( "About",
routes.MapRoute(
"About",
"About/{id}",
new { controller = "About", action = "Index" }
);
第二,无参数,显示一般事物
routes.MapRoute(
"About",
"About",
new { controller = "About", action = "Index" }
);
如何构建路线以接受这两个选项
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
...
}