c# - Html.RenderPartial 上的 MVC System.Web.HttpCompileException

标签 c# asp.net-mvc razor partial-views

当我的 View 调用 Html.RederPartial 时,我得到一个 System.Web.HttpCompileException。异常信息是:

Additional information: External component has thrown an exception.

我已经检查过:

  • Controller 没有抛出异常
  • 局部 View 确实存在
  • Controller 传递的模型和 View 接收的是一样的。
  • InnerException 为空

异常听起来应该是 html 或 razor 格式不正确或不正确,但解决方案构建良好。它也在不久前工作,所以我猜,我错过了一些愚蠢的东西......

我的问题:

有谁知道如何知道导致此异常的原因?或者有没有办法获得有关异常的更多信息?

编辑:这是 StackTrace

at System.Web.Compilation.AssemblyBuilder.Compile() at System.Web.Compilation.BuildProvidersCompiler.PerformBuild() at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean ...

最佳答案

原来这是我犯的一个愚蠢的错误。 MVC 无法从 Razor 编译 Html,因为我在 Model 中重命名了一个属性,但没有在 中更新它>.cshtml

在编译时打开 Razor Build 错误。编辑您的 csproj 文件并设置以下内容:

<MvcBuildViews>true</MvcBuildViews>

感谢 JP 提供此 SO post .

关于c# - Html.RenderPartial 上的 MVC System.Web.HttpCompileException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31608851/

相关文章:

c# - 如何在 C# 中重定向**现有**进程的 STD-Out

c# - 列表中的协方差

css - 网站发布时提供的 MVC 应用程序模板圆 Angular 消失

asp.net-mvc - MVC WebGrid 设置呈现的ID

c# - 如何使用 CSS 在同一行上对齐两个文本框

c# - 如何使用 .Net/Parse.com 发送 API 凭据和用户名/密码? (PHP 到 C#)

c# - 从 Windows 窗体中删除控件并调整其他控件以适应

c# - 确定客户端的计算机名称

javascript - 我正在尝试使用 mvc JavaScript 函数启用/禁用下拉菜单

asp.net-mvc-3 - 显示数据库中的文本时保持空格