3
我有一個多區域的MVC3應用程序。每個區域都是不同的應用程序模塊,但它們共享一個通用功能 - 報告。所以,我編寫了一個報告控制器和根區域的視圖,並希望使用路由將它們附加到所有區域。這種方法與MVC1效果很好,但後來我升級到MVC3,航線停止工作,並始終返回404MVC3:一個控制器,多個路徑
配置結構的每一個模塊/地區相似:
Module1/Reports.aspx/
Module1/PreportView.aspx/{id}
Module1/{controller}/{action}
Module1/{controller}/{action}/{id}
和模塊的路線註冊通過以下方法制備:
protected override void RegisterRoutes(AreaRegistrationContext context, string arearoot, string defaultControllerName){
context.MapRoute(arearoot + "Reports", arearoot + "/Reports.aspx",
new { action = "Index", controller = "Reports" }, new string[] { "Controllers" }); //this should work in MVC3 according to docs
context.MapRoute(arearoot + "ReportView", arearoot + "/ReportView.aspx/{id}",
new { action = "Show", controller = "Controllers.ReportsController" });//this method worked in MVC1
context.MapRoute(arearoot,
arearoot + "/{controller}.aspx/{action}",
new { controller = defaultControllerName, action = "Index" },
GetRouteNamespaces());
context.MapRoute(arearoot + "ItemSpecific",
arearoot + "/{controller}.aspx/{action}/{id}");
}
protected string[] GetRouteNamespaces() {
return new string[] { "Controllers.Module1" }; //returns proper namespace for each module
}
我試圖附着RouteDebugger(其將失敗,因爲的.aspx擴展),以及一瞥,但他們都沒有給我帶來任何問題,路由表似乎沒問題,但是當我嘗試導航到報告時,我總是得到404錯誤代碼。
任何想法?
你怎麼罵的行動(在你的ASPX/C-文件)? – Tobias