在我的MVC2應用程序中,我有一個AccountController
類繼承自Controller
。我想實現以下功能:當用戶試圖打開Account/Payments/NewPayment
AccountController.ExecuteNewPayment()
方法應該被調用。如何將請求路由到MVC2中特定控制器中的特定操作?
我增加了以下路線:
routes.MapRoute(
@"CreateNewRuntime",
@"{langId}/Account/Payments/NewPayment/{whatever}",
new { langId = @"default", controller = @"Account", action = @"ExecuteNewPayment"});
但是當我嘗試上面我與「請求URL」 /Account/Payments/NewPayment
HTTP 404錯誤消息,當我這樣做在調試器下有一個例外
System.Web.Mvc.dll中發生類型'System.Web.HttpException'的第一次機會異常 附加信息:路徑'/ Account/Payments/NewPayment'的控制器未找到或未實現IController 。
我在做什麼錯?我如何執行映射?
很傷心。所以我必須指定一條額外的路線,以便'/ language/Account/Payments/NewPayment'/Account/Payments/NewPayment'映射到相同的控制器 - 操作對還是有更好的方法? – sharptooth
@sharptooth - 不幸的是,你需要一條適合這兩種風景的路線 – amurra