Last active
September 19, 2017 03:00
-
-
Save teamtam/aa43d43607dd928e2bef117dc24be4ec to your computer and use it in GitHub Desktop.
ASP.NET Core customisation for arranging views vertically by feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ViewLocationExpander : IViewLocationExpander | |
{ | |
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations) | |
{ | |
string[] locations = new string[] | |
{ | |
"~/Features/{1}/{0}.cshtml", | |
"~/Features/Shared/{0}.cshtml", | |
}; | |
return locations; | |
} | |
public void PopulateValues(ViewLocationExpanderContext context) | |
{ | |
context.Values["customviewlocation"] = nameof(ViewLocationExpander); | |
} | |
} | |
// Then in Startup.cs ... | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
// ... | |
services.AddMvc(); | |
services.Configure<RazorViewEngineOptions>(options => { options.ViewLocationExpanders.Add(new ViewLocationExpander()); }); | |
// ... | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment