Use An Area In ASP.NET Core

CheapASPNETHostingReview.com | Best and cheap ASP.NET Core hosting.  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.

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).

Now, we will create a Controller inside the Controllers folder named AdminController.

Now, in order for that to work, you’ll need to create Views for all actions that return one. The hierarchy for Views is just like what you have in a non-area Views folder.

Question – What if I want to have another Controller inside my Area?

Answer 

Just add another Controller beside AdminController and make sure the routes are like the following,

The important part is [Route(“admin/[controller]”)]. With that, you can keep the style of routing to admin /controller/ action/.