c# - ASP.NET MVC 4,为什么自定义引擎找不到 View

标签 c# asp.net-mvc

<分区>

我有一类自定义 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。当然,两个引擎的文件夹结构相同

最佳答案

对不起,这是文件夹命名的问题。问题解决了

关于c# - ASP.NET MVC 4,为什么自定义引擎找不到 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38394091/

相关文章:

c# - 从图像中获取元数据 C#

asp.net-mvc - 如何处理 ASP.NET MVC 中动态生成的表单的输出?

c# - 依赖注入(inject)可选参数

asp.net-mvc - mVC 中的 SetFoucsOnError

c# - 我需要在客户端计算机上安装 SQL Server 吗?

c# - 使用带有日期时间和 bool 值的自动映射器来表示 POCO 中的半天

C# 根据多个条件对列表进行排序

c# - 为什么我的 ValidationMessageFor For TextArea 在页面加载时显示

c# - Azure 网站.well-known 路由变得无法访问

c# - 是否可以在没有标准类和 namespace 的情况下创建自己的身份验证?