Nested areas in MVC 2 / MVC 3 / MVC 4

With MVC 2, we can easily create areas. Now my question is related to nested areas (areas within areas).

Select the father folder, right-click> Add > NO option for new Area .

Can this be done in another way? or will this option be available in the near future?

+7
asp.net-mvc-3 asp.net-mvc-4 asp.net-mvc-2
source share
6 answers

I understand that this is an old question, but I will answer it if someone else tries to figure it out. The solution to this is to create areas that use a different routing value at a lower level than the area, so for example, your RouteConfig will look something like this:

 public class RouteConfig { /// <summary> /// A function that registers the default navigation route. /// </summary> /// <param name="routes">The RouteCollection to act on.</param> public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); var route = routes.MapRoute( name: "Default", url: "{area}/{subArea}/{controller}/{action}/{id}", defaults: new { area = "DefaultArea", controller = "Home", action = "Splash", id = UrlParameter.Optional, section = "Customer" }, namespaces: new string[] { "Application.Controllers" }); } } 

And one of your subzone registrations might look like this:

 public class ApplicationSubAreaRegistration : AreaRegistration { public override string AreaName { get { return "ApplicationSubArea"; } } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "SubArea_default", "Area/SubArea/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional }, new string[] { "Application.Areas.AreaName.SubAreaName.Controllers" } ); } } 

After reading this question, does "area" still look like a word? Because it is not for me.

PS You can do this recursively as many times as you want (theoretically), for example, you could do

 url: "{area}/{subArea}/{subSubArea}/{subSubSubArea}/{evenMoreSubArea}/{controller}/{action}/{id}", 

in your RouteConfig.cs and

 "Area/SubArea/SubSubArea/SubSubSubArea/EvenMoreSubArea/{controller}/{action}/{id}", 

in your area.

+4
source share

There is no information yet on whether there will be nested areas.

In the future, perhaps this will change.

+3
source share

Using the idea of multi-project areas at the beginning, I think you could recursively create more nested areas.

+2
source share

You do not want to have nested aers. There is something wrong with your software.

the most common case is that you use areas like the Html Renderer, therefore they are displayable templates.

0
source share

Maybe something like this can help. This is more like research, which is located in mvc-contrib. I saw it for version 1, I don’t know if it is compatible for MVC2. This is the concept of subcontrollers: http://mhinze.com/subcontrollers-in-aspnet-mvc/

0
source share

At this time, MVC only supports the main application, and then areas at the next level and NOT nested areas, but you can see this Nuget package that adds the following functions to your project:

  • Organize your controllers and views using namespaces (no more than areas) that can be as deep as you want.
  • Default restrictions for primitive types that can be overridden for each parameter or for each site.
  • Intelligent grouping of similar routes for efficient matching.
  • Support for the root controller.
  • Support for overloaded actions.
  • Support for hierarchical routes (aka RESTful).
  • Support for user defined user routes.
  • Detection of ambiguous routes.
  • Route formatting (e.g. lowercase, hyphen, underscore separation, etc.).
  • Send your routes as calls to the MapRoute extension method for debugging.
  • Support for inline views (as build resources).
0
source share

All Articles