ASP.Net MVC - 视图中的编译器错误

时间:2022-08-02 16:38:36

I wonder if anyone can explain why Visual Studio does not report compile errors on the View Pages?

我想知道是否有人可以解释为什么Visual Studio不会在View页面上报告编译错误?

I ask because I noticed that Re-Sharper (At least i think it is) picks up the fact that I have included a dead referance in my view but the project will build.

我问,因为我注意到Re-Sharper(至少我认为是这样)发现了我在视图中包含了一个死亡的事实,但项目将会建立起来。

eg,

例如,

<%@ Import Namespace="Site.This.Is.Dead.Link"%>

Its only when navigating to the page that this error is displayed. I think with MVC, as there is some logic and referances in the View, it would be a good thing for the compiler to report the error. However i'd like to know if there is a solid reason that this not be the case?

只有在导航到页面时才会显示此错误。我认为在MVC中,由于View中存在一些逻辑和反馈,编译器报告错误将是一件好事。但是,我想知道是否有一个坚实的理由不是这种情况?

1 个解决方案

#1


31  

To let you detect these errors at compile time, ASP.NET MVC projects now include an MvcBuildViews property, which is disabled by default. To enable this property, open the project file and set the MvcBuildViews property to true, as shown in the following example/image below:

为了让您在编译时检测到这些错误,ASP.NET MVC项目现在包含一个MvcBuildViews属性,默认情况下禁用该属性。要启用此属性,请打开项目文件并将MvcBuildViews属性设置为true,如下面的示例/图像所示:

    <MvcBuildViews>true</MvcBuildViews>

#1


31  

To let you detect these errors at compile time, ASP.NET MVC projects now include an MvcBuildViews property, which is disabled by default. To enable this property, open the project file and set the MvcBuildViews property to true, as shown in the following example/image below:

为了让您在编译时检测到这些错误,ASP.NET MVC项目现在包含一个MvcBuildViews属性,默认情况下禁用该属性。要启用此属性,请打开项目文件并将MvcBuildViews属性设置为true,如下面的示例/图像所示:

    <MvcBuildViews>true</MvcBuildViews>