MVC .NET Core Area


InterServer Web Hosting and VPS
Sony Playstation PS4 Pro Custom Build NVMe SSD Drive - Enclosure case and Crucial NVMe SSD
PS4 Pro Custom External SSD NVMe Drive

How I built a PS4 Pro Custom External SSD NVMe Drive...

NUC8i7BEH with memory
Intel NUC8I7BEH Review and Custom Build

This is my review of the Intel NUC8i7BEH and a summary of my build...

Card image cap
Asus M5A88-M EVO Review

This is my review of the Asus M5A88-M EVO motherboard...

Corsair Vengeance Blue 8GB (2x4GB) DDR3 PC3-12800C9 1600MHz Dual Channel Kit
Corsair Vengeance Blue Review

This is my review of the Corsair Vengeance Blue 8GB (2x4GB) DDR3 PC3-12800C9 1600MHz Dual Channel Kit memory...

Robotic Arm with USB PC Interface Review
Robotic Arm with USB PC Interface Review

This is my review of the Robotic Arm with USB PC Interface...

MVC .NET Core Area

Here we look at the MVC .NET Core Area.

The MVC Area in .NET Core helps us to organise our folder structure of files, specifically the Models, Controllers and Views. So if you'd like to group certain Models, Views and Controllers into groups, as in parent folders, the .NET Core MVC Area facility allows us to do this whilst maintaining the functionality of the Models, Views and Controllers.

Add an MVC .NET Core Area

In order to get the Area working in .NET Core 3.1 I had to do the following in Startup.cs:


app.UseEndpoints(endpoints =>
{
     endpoints.MapControllerRoute(
         name: "MyArea",
         pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");


     endpoints.MapControllerRoute(
         name: "default",
         pattern: "{controller=Home}/{action=Index}/{id?}");

     endpoints.MapRazorPages();
});

Note the .MapRazorPages call was only needed for ASP.NET Core Identity, so you may not need that, but hopefully useful if you do.

Additionally on the Controller I needed to added the [Area] attribute:


namespace High_Flying.Areas.Editor.Controllers
{
     [Area("Editor")]
     public class HomeController : Controller
     {
         private readonly ILogger _logger;

The file structure looks like this:


Areas
     Editor
         Controllers
             HomeController
         Data
         Models
         Views
             Home
                 Index.cshtml


Sponsored Links
SolarSystem - AngularJS Demo
SolarSystem - Angular JS Demo

Check out my first Angular JS demo hosted in Azure, it helped win my first Angular contract. Put the sound on.