我已經爲我的ASP.Net MVC 2網站的以下網址:ASP.Net MVC路線混亂
http://localhost:1919/TimeEntry/SummaryForWeek/15/2011
http://localhost:1919/TimeEntry/SummaryForMonth/4/2011
這兩項均創下該航線:
routes.MapRoute
(
"TimeEntryActionMonthYear", // Route name
"TimeEntry/{action}/{month}/{year}", // URL with parameters
new { controller = "TimeEntry", action = "Summary", month = UrlParameter.Optional, year = UrlParameter.Optional } // Parameter defaults
);
爲SummaryForWeek的動作期望一個名爲「weekNumber」的參數(上面的URL中的15值),而正在使用的路由傳遞一個名爲「month」的參數,因此weekSummary的URL失敗。將SummaryForWeek的參數從一週改爲月份是沒有意義的,只是路由才起作用。
我應該爲「SummaryForWeeks」硬編碼添加一個路由路由表,其中{action}是硬編碼的嗎?由於它膨脹了路線表,這沒有意義。
我不理解什麼(我知道這讓我想起了一些創造性的評論)?我卡住了。
感謝
湯姆
綁定問題:http://stackoverflow.com/questions/2743223/asp-net-mvc-routing-id-parameter/4304147#4304147 – 2011-04-14 21:22:29