ASP.Net 5 Areas

Visual Studio 2015 with ASP.Net 5 doesn’t support Areas in the GUI editor. Hopefully that will come, but until then here is a simple workaround.

Create folder structure

In the root of your project (not wwwroot) create the folder structure for Areas manually. In this example I created an area named “Foobar”.

image

Edit Startup.cs to add routes for areas

Change routes under “Configure” in Startup.cs. Inside app.UseMvc() you need to include a route for areas.

The whole section will look something like this:

Create Controller and specify Area

Create a controller named “HomeController.cs” under “Controllers”.

image

Add an Area tag to the class to specify which area to look for the View under.

Create view

The view is then placed under Views in a sub-folder corresponding to the controllers name.

image

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Tedds blog

Subscribe now to keep reading and get access to the full archive.

Continue reading