【问题标题】:MVC3 app ignoring Razor .cshtml extensionMVC3 应用程序忽略 Razor .cshtml 扩展名
【发布时间】:2011-03-01 11:17:59
【问题描述】:

我第一次尝试使用 Razor Web 项目运行 MVC3。该项目由 S#arp Architecture 生成,因此可能缺少一些接线。

已在 Views 文件夹下创建了带有 Razor 条目的事实上的 web.config。这是 ~/

的错误
[InvalidOperationException: The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Index.aspx
~/Index.ascx
~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx]

知道缺少什么吗?谢谢。

【问题讨论】:

    标签: asp.net asp.net-mvc-3 razor asp.net-mvc-routing


    【解决方案1】:

    添加

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

    Application_Start()
    

    在 Global.asax.cs 中

    成功了

    【讨论】:

    • 为什么需要这个?我在默认的 MVC3 项目中看不到这一行。谢谢。
    • 视图引擎是可插拔的。我只能猜测 mvc 3 架构师假设我们默认不需要剃须刀!?
    猜你喜欢
    • 2016-11-11
    • 2013-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-07
    相关资源
    最近更新 更多