带有错误的 razor 语法在不应编译时编译 [英] razor syntax with errors compiles when it should not compile

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

问题描述

所以我的 asp.net mvc3 应用程序在运行时遇到了一个错误,当我检查代码时,我看到它上面有一条红线,错误列表在那里说没有定义这样的函数它仍然可以编译.错误仅在运行时出现?我正在使用 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?

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

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 更改为 true


<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<代码>...
true
...

重新加载项目

下次编译时,如果 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.

更新

这是一个答案 关于 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

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

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