我是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
Run Code Online (Sandbox Code Playgroud)
因此,基本上查找键是域之后的第一个项目.URL的任何后续部分都映射到该航班的特定视图.
看似简单,但我似乎无法弄清楚如何构建控制器和路线...
试试这个
routes.MapRoute(
"YourRouteName", // Route name
"{flightNumber}/{action}", // URL with parameters
new { controller = "YourController", action = "YourDefaultAction", flightNumber = 0 } // Parameter defaults
);
Run Code Online (Sandbox Code Playgroud)
您应该将它放在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
| 归档时间: |
|
| 查看次数: |
2894 次 |
| 最近记录: |