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
andobj
folders. - Closing VS and reopening it (even with a reboot in the middle).
Note: I'm using Visual Studio 2012.
Open your web.config file located inside of Views folder and add this section if it's missing:
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 hadCopy Local
set toTrue
. After changing that everything started working great.