ASP.NET MVC 4,为什么自定义引擎找不到视图

本文关键字:自定义 引擎 找不到 视图 为什么 NET MVC ASP | 更新日期: 2023-09-27 17:57:15

>我有一类自定义视图引擎和 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 中的这 2 个引擎

ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new MyViewEngine("First"));
ViewEngines.Engines.Add(new MyViewEngine("Second"));
查找"在"第二视图引擎下"的视图

没有问题,但找不到"低于"的视图。我可以看到在ViewEngineResult中搜索的位置是正确的,引擎应该可以看到我的视图;我的视图名称也是正确的,但视图引擎结果仍然在视图属性中返回空值。当然,两个引擎的文件夹结构是相同的

ASP.NET MVC 4,为什么自定义引擎找不到视图

抱歉弄错了,这是文件夹命名的问题。问题已解决