如何启用优雅回退到“root”如果在区域中找不到控制器,则控制器
我有一个 ASP.NET MVC3 Razor 应用程序变得太大而无法有效管理。 为了更好地控制代码,我实现了区域并将代码重新排列在各自的区域中。
从多个区域使用的东西留在“正常”控制器文件夹中。
当我从某个区域使用 Action 或 ActionLink 时,我的问题就会出现。 我必须手动包含一个名为“area =”“”的路由参数才能使链接正常工作。
有很多链接需要更改,因此我尝试将控制器选择回退到“根”控制器以查找所需的控制器。 到目前为止我还没有运气。
如果没有找到控制器,我需要做什么才能使 MVC3 搜索区域控制器并继续在根控制器文件夹中搜索?
谢谢 安德烈亚斯
I have an ASP.NET MVC3 Razor application getting too big to manage effectively.
To have better control over the code I implemented Areas and re-arranged the code to be in the respective areas.
Things that are used from multiple areas are left in the "normal" controller folder.
My problem arises as soon as I use an Action or ActionLink from an area.
I have to manually include a routing parameter called 'area = ""' to have the link work.
There are a lot of links to be changed, so I tried to have the controller selection fallback to the "root" controllers to find the needed controller.
I had no luck so far.
What do I have to do to enable MVC3 to search through the area controllers and continue to search in the root controllers folder if the controller is not found?
Thanks
Andreas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过适当设置路线来做到这一点。
每个地区都有自己的航线供应商,然后在global.ascx中有航线。路由的行为有点像 case 语句,它首先尝试在区域中查找路由,如果找不到匹配的路由,则它会转到 global.ascx 路由。
因此,在您的新区域中,设置一个包罗万象的路线,并在 global.ascx 中设置一个包罗万象的路线,您应该没问题。
您可以使用 Haack 的 路由调试器来查看发生了什么与你的路线。
You can do this by setting up your routes appropriately.
Each area has it's own route supplier, and then there are the routes in the global.ascx. The routes act sort of like a case statement, where it tries to find the routes in the areas first, and if it doesn't find a matching route, it then falls through to the global.ascx routes.
So, in your new areas, setup a catchall route, and in the global.ascx setup a catchall route and you should be ok.
You can use Haack's route debugger to see what is happening with your routes.