<分区>
我有一类自定义 View 引擎 和从此类派生的 2 个引擎
public class MyViewEngine : RazorViewEngine
{
public string UIFramework { get; set; }
public MyViewEngine(string uiFramework)
{
UIFramework = uiFramework;
this.ViewLocationFormats = new[]
{
string.Format("~/Views/{0}/{{1}}/{{0}}.cshtml", this.UIFramework ?? string.Empty),
string.Format("~/Views/{0}/{{1}}/{{0}}.vbhtml", this.UIFramework ?? string.Empty),
string.Format("~/Views/{0}/{{1}}/{{0}}.aspx", this.UIFramework ?? string.Empty),
string.Format("~/Views/{0}/{{1}}/{{0}}.ascx", this.UIFramework ?? string.Empty),
};
this.PartialViewLocationFormats = new[]
{
string.Format("~/Views/{0}/Shared/{{0}}.cshtml", this.UIFramework ?? string.Empty),
string.Format("~/Views/{0}/Shared/{{0}}.vbhtml", this.UIFramework ?? string.Empty),
string.Format("~/Views/{0}/Shared/{{0}}.aspx", this.UIFramework ?? string.Empty),
string.Format("~/Views/{0}/Shared/{{0}}.ascx", this.UIFramework ?? string.Empty),
};
this.MasterLocationFormats = new[]
{
string.Format("~/Views/{0}/Shared/{{0}}.cshtml", this.UIFramework ?? string.Empty),
string.Format("~/Views/{0}/Shared/{{0}}.vbhtml", this.UIFramework ?? string.Empty),
string.Format("~/Views/{0}/Shared/{{0}}.aspx", this.UIFramework ?? string.Empty),
string.Format("~/Views/{0}/Shared/{{0}}.ascx", this.UIFramework ?? string.Empty),
};
}
}
以及 Global.asax 中的这两个引擎
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new MyViewEngine("First"));
ViewEngines.Engines.Add(new MyViewEngine("Second"));
在“第二个” View 引擎“下”查找 View 没有问题,但找不到“第一个”下的 View 。我可以看到在 ViewEngineResult 中搜索的位置是正确的,引擎应该看到我的 View ;我的 View 名称也是正确的,但 ViewEngineResult 仍然在 View 属性中返回 null。当然,两个引擎的文件夹结构相同