How To Use An Area In ASP.NET Core

In order to include an Area in an ASP.NET Core app, first we need to include a conventional route in the Startup.cs file (It's best to place it before any non-area route).

In Startup.cs, configure the method.

  1. app.UseMvc(routes =>
  2. {
  3. routes.MapRoute("areaRoute", "{area:exists}/{controller=Admin}/{action=Index}/{id?}");
  4. routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}");
  5. });

Then, make a folder named Areas in the app root and make another directory named Admin inside the former. Inside the admin folder, create the following folders (ViewComponent is optional).