Html.RenderPartial 上的 MVC System.Web.HttpCompileException

MVC System.Web.HttpCompileException on Html.RenderPartial

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

Additional information: External component has thrown an exception.

我检查过:

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

我的问题:

有谁知道怎么知道是什么原因导致了这个异常?或者有没有办法获得有关异常的更多信息?

编辑:这是 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

我发现我的 HTML 部分文件之一,即 *.cshtml 文件缺少引用。通常,当任何 cshtml 页面有错误时,在编译时不会显示,但您可以使用调试点跟踪它

我们解决了“外部组件抛出异常”的问题。通过回收应用程序池发出。这是做其他事情之前的快速方法。