I would like to create a project structure with nested areas. For instance I have a "Home" area and underneath this I would like the "News" area that handles it's own route registration and will properly find views when a route points to a controller in the "News" area. By changing the "News" area name to be "Home/News" instead of simply "News", the proper views are found. In the main Global.asax.cs, I instantiate all of the areas ("Home" and "News") and register them individually because the RegisterAllAreas() function only finds areas one level deep (i.e. it only finds and registers the "Home" area).
Has anyone else tried something similar? Is this a major hack or can this be a stable long-term solution? Any advice you can offer is much appreciated.
You can create an area by right-clicking on the project in the solution explorer -> Add -> Area.. , as shown below. Enter the name of an area in the Add Area dialogue box and click on the Add button. This will add an admin folder under the Area folder, as shown below.
Add MVC Area with Visual StudioIn Solution Explorer, right click the project and select ADD > New Scaffolded Item, then select MVC Area. Areas are an ASP.NET feature used to organize related functionality into a group as a separate namespace (for routing) and folder structure (for views).
in short, an area can be defined as: smaller functional units in an asp.net mvc project with its own set of controllers, views, and models . a single mvc application may have any number of areas. some of the characteristics of areas are: an mvc application can have any number of areas.
Areas allows you to separate your modules and organize Model, View, Controller, Web. config and Routing registration file into separate sections. In live MVC Project implementation we can use Areas concept for organizing project in better manageable way. Area separate logical section like Model, View, Controller, Web.
You can do it with MvcCodeRouting, a seprate open-source CodePlex project.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With