在撰寫本文時(3月-10-2016),官方的ASP.NET文檔"Creating a Custom View Engine" (Page 299)不可用。
我正在使用「Microsoft.AspNet.Mvc」同樣的錯誤:「6.0.0-RC1決賽」,但因爲我的意圖只是包括附加視圖位置,我解決它:
public class CustomViewLocationExpander : IViewLocationExpander
{
public void PopulateValues(ViewLocationExpanderContext context)
{
}
public virtual IEnumerable<string> ExpandViewLocations(
ViewLocationExpanderContext context,
IEnumerable<string> viewLocations)
{
return viewLocations.Union(new string[] { "~/Views/{1}/PartialViews/{0}.cshtml" });
}
}
,並添加代碼Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvc()
.AddRazorOptions(options =>
{
options.ViewLocationExpanders.Add(new CustomViewLocationExpander());
})
.AddViewLocalization(LanguageViewLocationExpanderFormat.SubFolder);
}
我希望能幫助你以某種方式。