Areas in ASP.Net MVC

In the previous blog, I wrote about Filters in MVC.
In this blog, we will see What is Area in ASP.Net MVC?

What is Area in MVC?

The Area in MVC is basically a part of the project. It means an application could have the different section such as Admin, Users or Customers, Moderator, Editor, Author etc.
In such condition, we can create Areas for all the sections. Area is used in large application only.

Why use Areas in MVC?

The Area contains their own views, model, and controllers which makes a large application easier to maintain.
To add Areas in your project, right click on your project, select Add and click on Area. See below screenshot for your ref.

Give a name to the Area, in my case it is Customer. Now, you will find a new Folder with name Areas having Customers as a folder and a set of Models, Views and Controllers
You may find a new class has been added, CustomersAreaRegisteration.cs which contains below code:
public class CustomersAreaRegistration : AreaRegistration
    {
        public override string AreaName
        {
            get
            {
                return “Customers”;
            }
        }
        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                “Customers_default”,
                “Customers/{controller}/{action}/{id}”,
                new { action = “Index”, id = UrlParameter.Optional }
            );
        }
    }
All Area classes inherit AreaRegisteration class which has a property called AreaName.
So, this is the basics of Area in ASP.Net MVC. Hope you like this blog.
Please share this blog, like our Facebook page and comment down below in case of any query.
Other Blogs on MVC –

Leave a Comment

RSS
YouTube
YouTube
Instagram