Skip to content

Instantly share code, notes, and snippets.

@teamtam
Last active September 19, 2017 03:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teamtam/aa43d43607dd928e2bef117dc24be4ec to your computer and use it in GitHub Desktop.
Save teamtam/aa43d43607dd928e2bef117dc24be4ec to your computer and use it in GitHub Desktop.
ASP.NET Core customisation for arranging views vertically by feature
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