Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
485 views
in Technique[技术] by (71.8m points)

asp.net mvc - razor syntax with errors compiles when it should not compile

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?

enter image description here

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

It fails at runtime :

enter image description here

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

  • Right click on your project in Visual Studio
  • Unload project
  • Edit project

  • 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>
    ...

  • Reload project

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.

Update

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...