View Location Expander in ASP.NET 5 / MVC6

If you are using MVC and your backend is getting bigger and bigger you will start to structure it more aggressively.

For example in a project I had to move my "Views" into a subfolder like this:

 

 

 

The Problem

The default RazorViewEngine's view path is at '/Views' and not  '/Core/Views'.

 

The Solution

There is an easy way in MVC6 to add or replace view paths. The feature is called View Location Expander.

In my case I don't have any other "Views" folder, so I decided to replace the default view location.

 

Example:

 This defines a custom view location expander that will override the default path.

 

 

How to add it to your Startup.cs:

 We configure the DI-Container by adding / customizing a service.

 

 

Well that's it. Pretty, nice and easy :)

 

 

 



Mahmut Jomaa is a Software Engineer from Germany.

Currently he attends university to gain more knowledge in Computer Science.


Security code Refresh