我有一个包含多个区域的 MVC 4 网站...我正在使用 VS2012 创建的所有默认路由...
所以,我可以访问(从Area1):
Area1/ControllerX/ActionX
我有一些没有区域的控制器,所以我可以访问:
ControllerY/ActionY
一切都很好......但是,如果我尝试在没有 Area1 的情况下访问 ControllerX,就像这样:
ControllerX/ActionX
我得到了那个错误:
Exception: The view 'ActionX' or its master was not found or no view engine supports the
searched locations. The following locations were searched: ~/Views/mangavagao/ActionX.cshtml
~/Views/Shared/ActionX.cshtml
Controller: ControllerX
Action: ActionX
我期待一个 Not Found 404 错误...为什么该路由被捕获?
--
区域路线:
context.MapRoute(
"Area1_default",
"Area1/{controller}/{action}/{id}",
new { controller = "ControllerX", action = "ActionY", id = UrlParameter.Optional }
);
默认路由:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "ControllerY", action = "ActionY", id = UrlParameter.Optional );