有错误的语法剃须刀时,编译它不应该编译 [英] razor syntax with errors compiles when it should not compile

查看:125
本文介绍了有错误的语法剃须刀时,编译它不应该编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我的成与我的asp.net MVC3的应用程序,当我检查了code我看到它上有一个红色的线运行时错误,在错误列表没有定义这样的功能的,但它仍然编译细。该错误只在运行时显示出来?我使用的 T4MVC ,我希望它会帮助我躲闪这样的问题!?

So I an into an error at runtime with my asp.net mvc3 app, when I checked the code I see that it has a red line on it, the error list says there is no such function defined but it will still compile fine. The error shows up only at runtime? I'm using T4MVC and I was hoping it would help me dodge problems like this!?

这设计是还是我错在这里做什么?

Is this by design or am I doing something wrong here?

上面的code应该不能编译,因为没有这样的方法有!

The code above should NOT compile because there is no such method there!

无法在运行时:

这还挺事情发生了很多,不只是联合国定义的方法,但即使变量等。

This kinda of thing happens a lot, not just for un defined methods, but even variables, etc.

推荐答案

这是由设计。的MVC观点构建默认情况下禁用。您可以在Visual Studio一样,使你的MVC看法构建:

This is by design. The build of of MVC views is disabled by default. You can enable the build of your MVC views in Visual Studio like that:


  • 右键单击在Visual Studio
  • 您的项目
  • 卸载项目

  • 修改项目

更​​改 MvcBuildViews 从false为真正搜索结果<$值C $ C>&LT;?XML版本=1.0编码=UTF-8&GT; 结果
&LT;项目ToolsVersion =4.0DefaultTargets =生成的xmlns =htt​​p://schemas.microsoft.com/developer/msbuild/2003&GT; 结果
... 结果
&LT; MvcBuildViews&GT;真&LT; / MvcBuildViews&GT; 结果
...

Change the value for MvcBuildViews from false to true

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
<MvcBuildViews>true</MvcBuildViews>
...

刷新项目

下一次编译,有在你的MVC的观点错误,将无法编译。
不足之处是,编译过程将需要更长的时间。

Next time you compile and there are errors in your MVC views, it will not compile. The downside is, the compilation process will take longer.

更新

下面是一个<一个href=\"http://stackoverflow.com/questions/2566215/allowdefinition-machinetoapplication-error-when-publishing-from-vs2010-but-onl/2862996#2862996\">answer在SO,解释如何避免错误:

Here is an answer on SO, explaining how to avoid the error:

这是使用注册为allowDefinition =应用程序级别之外'MachineToApplication'的节是错误的。这个错误可以通过未被配置为在IIS

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

这篇关于有错误的语法剃须刀时,编译它不应该编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆