.net - ASP.NET MVC 2 中是否可以嵌套区域?

标签 .net asp.net-mvc asp.net-mvc-2 asp.net-mvc-areas

我想创建一个带有嵌套区域的项目结构。例如,我有一个“主页”区域,在它下面我想要“新闻”区域来处理它自己的路由注册,并且当路由指向“新闻”区域中的 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.

  1. Organize your controllers using namespaces (no more areas) that can go as deep as you want.
  2. Default constraints for primivite types that can be overriden on a per-parameter or per-site basis.
  3. Intelligent grouping of similar routes for efficient matching.
  4. Support for a root controller.
  5. Detection of ambiguous routes.
  6. Formatting of routes (e.g. make them lower case).
  7. Render your routes as calls to the MapRoute extension method, for debugging.
  8. Use the same namespace-based base route for organizing your Views.

关于.net - ASP.NET MVC 2 中是否可以嵌套区域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3730618/

相关文章:

asp.net-mvc - 如何进入云服务 "ASP.NET MVC 4 Web Role"?

asp.net-mvc-2 - RedirectToAction 返回错误的 url

c# - 比较两个列表时单元测试失败

c# - 如何在Winforms C#中获取按钮背景图片的名称

c# - 使用静态 MemcachedClient 的问题

c# - 为什么我的静态类没有在 ASP.NET MVC 中初始化?

c# - 什么数据库适合保存小图像

c# - 无法使用 MySQLConnection 连接到远程数据库

.net - 网络浏览器控制窃取快捷方式

c# - 错误 : redirect_uri_mismatch In Google Login in MVC Application