In this recipe, you will learn how to change the view location used per convention by ASP.NET Core MVC.
We will use the previous recipe and add some modifications to use a different view location.
- First, let's create a new views folder named
ViewsOld
. In this folder, we will copy_ViewImports.cshtml
and_ViewSart
/cshtml
from theViews
folder, and cut theProduct
views folder to paste it into theViewsOld
folder:
- Next, we create a folder named
Infrastructure
and create a C# class namedOldViewsExpander.cs
. This class will contain the following code:
public class OldViewsExpander : IViewLocationExpander { public IEnumerable<string> ExpandViewLocations (ViewLocationExpanderContext context, IEnumerable<string> viewLocations) { // rerturn all classic locations foreach (string location in viewLocations) { yield return location; } // return new locations yield return "/ViewsOld/Shared/...