创建一个 View Location Expander
为了能够更改视图位置,你需要实现 IViewLocationExpander。ExpandViewLocations 方法返回一个 IEnumerable<string>,其中包含要搜索的不同位置
public class MyViewLocationExpander : IViewLocationExpander
{
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
{
yield return "/CustomViewFolder/{1}/{0}.cshtml";
yield return "/SharedFolder/{0}.cshtml";
}
public void PopulateValues(ViewLocationExpanderContext context)
{
}
}