我想创建一个带有嵌套区域的项目结构。例如,我有一个“主页”区域,在它下面我想要“新闻”区域来处理它自己的路由注册,并且当路由指向“新闻”区域中的 Controller 时会正确地找到 View 。通过将“新闻”区域名称更改为“主页/新闻”而不是简单的“新闻”,可以找到正确的 View 。在主要的 Global.asax.cs 中,我实例化所有区域(“Home”和“News”)并单独注册它们,因为 RegisterAllAreas() 函数只找到一层深的区域(即它只找到并注册“Home” “区域)。
有没有其他人尝试过类似的东西?这是一个重大的黑客攻击还是一个稳定的长期解决方案?非常感谢您提供的任何建议。
最佳答案
你可以用 来做MvcCodeRouting ,一个单独的开源 CodePlex 项目。
MvcCodeRouting automatically creates the best possible routes for your ASP.NET MVC application.
- Organize your controllers using namespaces (no more areas) that can go as deep as you want.
- Default constraints for primivite types that can be overriden on a per-parameter or per-site basis.
- Intelligent grouping of similar routes for efficient matching.
- Support for a root controller.
- Detection of ambiguous routes.
- Formatting of routes (e.g. make them lower case).
- Render your routes as calls to the MapRoute extension method, for debugging.
- Use the same namespace-based base route for organizing your Views.
关于.net - ASP.NET MVC 2 中是否可以嵌套区域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3730618/