Please enable Javascript to correctly display the contents on Dot Net Tricks!

MVC Areas with example

  Author : Shailendra Chauhan
Posted On : 01 Jan 2013
Total Views : 154,291   
Updated On : 26 Sep 2016

Areas was introduced in MVC2 which allow us to organize models, views, and controllers into separate functional sections of the application, such as administration, billing, customer support, and so on. This is very helpful in a large web application, where all the controllers, views, and models have a single set of folders and that become difficult to manage.

Each MVC area has its own folder structure which allow us to keep separate controllers, views, and models. This also helps the multiple developers to work on the same web application without interfere to one another.

Registering Area

Before working with area, make sure you have registered your area with in the Application_Start method in Global.asax as shown below.

protected void Application_Start()
 //Register all application Areas



Always remember the order of registering the Areas must be on top, so that all of the settings, filters and routes registered for the applications will also apply on the Areas.

Creating Area

To add an area to an MVC application, right-click on the project item with in the Solution Explorer window and select Add>Area option as shown below.

Now a new prompt will appear, with in give the name of the area like "Department" and click Add button. Now the new Department Area has been cretaed as shown in below fig.

Now you have seen DepartmentAreaRegistration class has been created and in the RegisterArea method, a route for the area has been defined as shown below.

using System.Web.Mvc;
namespace Mvc4Area.Areas.Department
 public class DepartmentAreaRegistration : AreaRegistration
 public override string AreaName
 return "Department";
 public override void RegisterArea(AreaRegistrationContext context)
 new { action = "Index", id = UrlParameter.Optional }

Populating Area

Now you can create controllers, views, and models in the Department area like as below.

How to see view with in Areas

Now, let's see how to view your Index view with the help of Page Inspector as shown below.

What do you think?

I hope you have got what is Areas and how to use it with in the application. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

Free Interview Books
Hadoop Development cum Administration (Online)

7:00 AM-9:00AM IST

Know More
30 MAY
ASP.NET MVC with Angular4 Development (Online)

09:00 PM-11:00 PM IST(+5.30 GMT)

Know More
28 MAY
ASP.NET Core with Angular4 Development (Classroom)

10:30 AM-11:30 AM Weekend

Know More
28 MAY
ASP.NET Core with Angular4 Development (Classroom)

10:30 AM-11:30 AM Weekend

27 MAY
ASP.NET MVC with Angular4 Development (Classroom)

4:00 PM-5:30 PM Weekend

20 MAY
Angular2 and Angular4 Development (Online)

08:00 AM-10:00 AM IST(+5.30 GMT) Weekend

20 MAY
NodeJS with Angular4 Development (Classroom)

5:00 PM-6:30 PM Weekend

ASP.NET MVC with Angular4 Development (Online)

07:00 AM-09:00 AM IST(+5:30 GMT) M/W/F

ASP.NET Core Development (Online)

07:00 AM - 09:00 AM IST( TUS, THR)

29 APR
ASP.NET MVC with Angular2 Development (Classroom)

9:30 AM-11:00 AM

22 APR
MEAN Stack 2 Development (Classroom)

11:00 AM-12:30 PM Weekend

10 APR
Master Class ASP.NET MVC 5 with Angular2 Plus Angular4 Development (Online)

09:00 PM - 11:00 PM IST (M/W/F)

25 MAR
Xamarin Forms : Build Cross-platform Apps (Classroom)

8:00 AM-9:30AM Weekend