Areas In MVC With Example

What are Areas in MVC

Areas allows you to separate your modules and organize Model, View, Controller, Web.config and Routing registration file into separate sections.

Why we use Areas in MVC

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.config, Routing. So for example you have 30 controllers in your projects, rather then working on single controller folder,
we can classify the module wise controllers and separate it in different areas.
So, let us create a MVC Project first, for that follow the steps. 

Step 1
: Create a new ASP.NET Web Application project and select MVC Template.

 
 
Let us create Areas for Teachers Module and Students Module.
 
Step 2: Right click on Project and add Area and give it name 'Teachers'. 
 
 
 
 
So, inside Areas folder it creates Teachers Module, similarly let us create a Student Module. You can see here each module has separate Model, View, Controller, Web.config and Routing Registration file.
 
 
 
 
Step 3: Let us add a controller in Students area by right click on Controllers folder, then Add, Controller.
 
 

Select MVC 5 Controller - Empty Template, and give name Index.
 
 
Step 4: Create a view by right click on index, then Add view, and give name to view, here I gave Index
 
 
 
Now click on 'Ok'.
 


Step 5: Inside your Index.cshtml add some text like 'This is Student Dashboard' and build your application.

 
 
Now run your application and change url like the following: 'http://localhost/Students/Index'.
 


Same way you can run TeacherDashboard.
 


This allows the development team to easily manage their large project by separating Modules. Hope you like this article.


Similar Articles