我是MVC的新手,所以我在为下面的场景设置路由时遇到了一些问题。
假设我有一个站点,可以查找航班数据并显示每个航班的三个主要视图。
我希望URL结构如下所示:
www.domain.com/<flightnumber>/ <-- Main page for the flight
www.domain.com/<flightnumber>/crew <-- A page with details of the crew for that flight
www.domain.com/<flightnumber>/destination <-- details of the destination for the flight看起来很简单,但我似乎不知道如何构造控制器和路由……
发布于 2012-11-30 06:44:58
尝尝这个
routes.MapRoute(
"YourRouteName", // Route name
"{flightNumber}/{action}", // URL with parameters
new { controller = "YourController", action = "YourDefaultAction", flightNumber = 0 } // Parameter defaults
);您应该将其放在RouteConfig.cs (MVC4)或Global.asax (MVC3)的RegisterRoutes方法的顶部
您可以在asp.net站点http://www.asp.net/mvc/tutorials/older-versions/controllers-and-routing/asp-net-mvc-routing-overview-cs上阅读有关路由的更多信息
https://stackoverflow.com/questions/13633791
复制相似问题