Saturday, 22 December 2018

What is the use of Area in MVC

To make the modular design, Areas are used in MVC application. When we are working with large applications maintaining the business logic and UI is difficult when the application grows. To make it simple and maintainable Areas are used in MVC application.

When we add an Area it has its own Controler, Model, View, Routes and AreaRegistration.cs folder. We can add a meaningful area in the application and its related contents in that. So in long run, it will be easier to maintain and debug the application. AreaRegistration.cs file contains the code to register a route for the area.

When you add an Area it will add AreaRegistration.RegisterAllAreas() in Application_Start() method.

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    WebApiConfig.Register(GlobalConfiguration.Configuration);
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
}

While accessing the areas you need to explicitly define the area name in the View.

@Html.ActionLink("Employee Area Home Page""Index""Home"new { area = "YourAreaName" }, null)


No comments:

Post a Comment