【问题标题】:MVC 3 Razor - How to stop the view engine from searching the aspx and ascx pages?MVC 3 Razor - 如何阻止视图引擎搜索 aspx 和 ascx 页面?
【发布时间】:2014-01-04 04:32:55
【问题描述】:

我在视图中有一个小错误,并注意到视图引擎不仅在搜索我的剃须刀视图,而且还在搜索 aspx/ascx 页面。 (我的错误已修复)

有没有办法让它只搜索 Razor 视图引擎?

这是显示的错误消息:

The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Areas/BO/Views/Organization/Index.aspx
~/Areas/BO/Views/Organization/Index.ascx
~/Areas/BO/Views/Shared/Index.aspx
~/Areas/BO/Views/Shared/Index.ascx
~/Views/Organization/Index.aspx
~/Views/Organization/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Areas/BO/Views/Organization/Index.cshtml
~/Areas/BO/Views/Organization/Index.vbhtml
~/Areas/BO/Views/Shared/Index.cshtml
~/Areas/BO/Views/Shared/Index.vbhtml
~/Views/Organization/Index.cshtml
~/Views/Organization/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml

【问题讨论】:

    标签: c# asp.net-mvc-3 razor


    【解决方案1】:

    您需要从ViewEngine.Engines 中删除WebFormsViewEngine,使其仅包含RazorViewEngine

    例如:

    ViewEngines.Engines.Clear();
    ViewEngines.Engines.Add(new RazorViewEngine());
    

    【讨论】:

    • 我会把它放在 app_start 上?
    • 无论如何也要删除 .vbhtml?
    • @Eddie:将RazorViewEngineFileExtensions 设置为new[] { "cshtml" }
    • 这对我不起作用 - Application_Start() 中的前两行:ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new RazorViewEngine { FileExtensions = new[] { "cshtml" } });
    【解决方案2】:

    如果您希望在 ViewEngines 中使用自定义扩展,并且设置 ViewEngine.FileExtensions = new[] { "cshtml" } 的建议对您也不起作用,请查看相关问题:Make ASP.NET MVC 3 Razor View Engine ignore .vbhtml files

    特别是我的回答(或其他人真的)https://stackoverflow.com/a/20912185/1037948

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-03
      • 1970-01-01
      • 2012-06-24
      相关资源
      最近更新 更多