建立一個 View Location Expander

為了能夠更改檢視位置,你需要實現 IViewLocationExpanderExpandViewLocations 方法返回一個 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)
    {            
    }
}