【发布时间】:2014-11-17 21:36:54
【问题描述】:
背景故事:
我的公司有几个大型的独立应用程序,我们将它们合并为一个应用程序。在研究的过程中,我使用了一个 MVC 应用程序,每个应用程序都位于区域文件夹中。所以结构是
- 应用
- 区域
- 应用程序 1
- 控制器
- WorkWithReceipts
- 收据控制器
- SomethingElseController
- 文件维护
- MainSetupController
- WorkWithReceipts
- 控制器
- 应用程序 2
- 控制器
- 草
- TreesController
- 树木
- TreesController
- 草
- 控制器
- 应用程序 1
- 区域
问题
所以我遇到的问题是我的路由。它总是使用顶部的,如果我尝试访问 MainSetupController,它会搜索 Controllers/WorkWithReceipts/MainSetup/[action],因为它位于 FileMaintenance 文件夹下。
这是我的路由配置。
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"FileMaintenance",
"Accounting/FileMaintenance/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Courts.Areas.Accounting.Controllers.FileMaintenance" }
);
context.MapRoute(
"Receipts",
"Accounting/Receipts/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Courts.Areas.Accounting.Controllers.Receipts" }
);
context.MapRoute(
"Accounting",
"Accounting/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Courts.Areas.Accounting.Controllers" }
);
}
问题
所以我想知道是否有办法设置我的路由,以便我的路由期望相同的参数,但是,根据传入的区域、控制器和操作,它会找到要使用的正确路由。现在它总是使用最顶层的路线。
【问题讨论】:
标签: asp.net-mvc routing