asp.net-mvc – 具有错误的剃刀语法编译时不应该编译

所以我在运行时与我的asp.net mvc3应用程序错误,当我检查代码,我看到它有一条红线,错误列表说没有这样的功能定义,但它仍然会编译好。该错误仅在运行时显示?我正在使用T4MVC,我希望能帮助我避免这样的问题!

这是设计还是我在这里做错事?

上面的代码不应该编译,因为没有这样的方法

它在运行时失败:

这种事情发生很多,不仅仅是针对未定义的方法,甚至是变量等。

解决方法

这是设计。认情况下禁用MVC视图的构建。您可以在Visual Studio中启用MVC视图的构建,如下所示:

>在Visual Studio中右键单击您的项目
>卸载项目
>编辑项目
>将MvcBuildViews的值从false更改为true<?xml version =“1.0”encoding =“utf-8”?>
< Project Toolsversion =“4.0”DefaultTargets =“Build”xmlns =“http://schemas.microsoft.com/developer/msbuild/2003”>

< MvcBuildViews>真< / MvcBuildViews>

>重新加载项目

下次编译时,您的MVC视图中有错误,将无法编译。
缺点是编译过程需要更长的时间。

更新

这是一个answer在SO,解释如何避免错误

It is an error to use a section registered as allowDeFinition=’MachinetoApplication’ beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...