2
我有一個類的自定義視圖引擎的 從這個類派生的2個引擎ASP.NET MVC 4,爲什麼定義引擎沒有找到一個視圖
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),
};
}
}
這些2個引擎在Global.asax中
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new MyViewEngine("First"));
ViewEngines.Engines.Add(new MyViewEngine("Second"));
查找「第二個視圖引擎下」視圖沒有問題,但未找到「下」第一個視圖。我可以看到,在ViewEngineResult搜索位置是正確的,發動機應該看到我的看法;而我的觀點的名稱是正確的太多,但仍然ViewEngineResult在查看property.Folders結構返回null是相同的,當然兩個引擎
嘗試註釋掉在Global.asax中的第二視圖引擎和看到的結果 – Marusyk