Please describes to me what is Area and how we create an Area in Asp.Net MVC using an example.
What is Area and how we create it in MVC?
224217-Feb-2020
Updated on 17-Feb-2020
Home / DeveloperSection / Forums / What is Area and how we create it in MVC?
Please describes to me what is Area and how we create an Area in Asp.Net MVC using an example.
Nishi Tiwari
17-Feb-2020The ASP.NET MVC framework includes separate folders for Model, View, and Controller, however, the large application can include a large number of controller, views and model classes, and so to maintain a large number of views, models, and controllers with the default the ASP.NET MVC project structure which can become unmanageable.
The ASP.NET MVC 2 introduced Area and this area allows us to partition large application into smaller units where each unit contains separate MVC folder structure, same as default MVC folder structure, for example, large enterprise application contains different modules like admin, finance, HR, marketing, etc. so an Area can contain separate MVC folder structure for all these modules as shown given below:-
Creating an Area
This following is the adminAreaRegistration class created with the admin area.
Here, the AreaRegistration class overrides RegisterArea method to map the routes for the area and in the above-given example, so any URL that starts with admin will be handled by the controllers which are included in the admin folder structure under Area folder, for example, http://localhost/admin/profile will be handled by the profile controller included in Areas/admin/controller/ProfileController folder.
At the end all the area must be registered in Application_Start event in Global.asax.cs as AreaRegistration.RegisterAllAreas();
In this way, we can create and maintain multiple areas for a large application.