c# - MVC 3 Razor - 如何阻止 View 引擎搜索 aspx 和 ascx 页面?

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

我在 View 中有一个小错误,我注意到 View 引擎不仅在搜索我的 razor View ,还在搜索 aspx/ascx 页面。 (我的错误已修复)

有没有办法告诉它只搜索 Razor View 引擎?

这是显示的错误消息:

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

最佳答案

您需要从 ViewEngine.Engines 中删除 WebFormsViewEngine,以便它只包含一个 RazorViewEngine

例如:

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

关于c# - MVC 3 Razor - 如何阻止 View 引擎搜索 aspx 和 ascx 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7727259/

相关文章:

c# - 打开 OLEDB 连接到 Excel 文件时 Windows 服务挂起

c# - 使用 CodeBehind 中的数据填充 GridView 中模板字段内的 DropDownList

javascript - 在 ASP.NET MVC 3 中使用 ajax 将 xml 字符串发送到 Controller

c# - 如何检查当前文档类型的祖先是否是 Umbraco 中的特定类型?

c# - 图像作为 GridView 中每列的标题

c# - 如何在没有 HTML 标签的情况下从数据库中获取数据?

ajax - MVC3-Ajax加载图标

c# - 使用 ASP.NET MVC 3 创建安全的高分服务

javascript - 模拟XSS攻击不起作用

c# - 不允许子操作执行重定向操作 - 使用 ASP.NET MVC 2 和 Razor 时出错