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
928 views
in Technique[技术] by (71.8m points)

asp.net mvc - Visual studio showing syntax errors in razor statements but works

I've a project in MVC 3. It works perfectly and each time I build it, it succeeds. However, Visual Studio insist in showing compile errors in views in each razor syntax. For example:

The name 'model' does not exist in the current context D: ... Detail.cshtml

That line is simple:

@model Namespace.DetailViewModel

I've already tried:

  • Cleaning solution
  • Cleaning solution and deleting bin and obj folders.
  • Closing VS and reopening it (even with a reboot in the middle).

Note: I'm using Visual Studio 2012.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

I've solved it!

The project was created when the computer didn't have MVC 4 installed yet. After installing it, for some reason, it kept working (despite this).

So what I did was make the changes that should be made in MVC 3 project after installing MVC 4: see here

After that, it compiled and the errors disappeared, however there was an error with the versions of some libraries (System.Web.WebPages, System.Web.WebPages.Razor, and some others). That turned out to be because they had Copy Local set to True. After changing that everything started working great.


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

...