After significant refactoring in my MVC 4 application, and Razor shows this error while debugging Views:
The name 'model' does not exist in the current context.
This is the offending line of code:
@model ICollection<DataSourceByActive>
I know that the usage of @model
is correct.
Why is this happening? How can I fix it?
None of the existing answers worked for me, but I found what did work for me by comparing the
.csproj
files of different projects. The following manual edit to the.csproj
XML-file solved the Razor-intellisense problem for me, maybe this can help someone else who has tried all the other answers to no avail. Key is to remove any instances of<Private>False</Private>
in the<Reference>
's:I don't know how those got there or exactly what they do, maybe someone smarter than me can add that information. I was just happy to finally solve this problem.
In my case, the issue was that after upgrading the project from MVC 4 to MVC 5 I somehow missed a version change in the Views/web.config:
It still had the old 2.0.0.0 version. After changing the version to 3.0.0.0 everything started working just right.
Also, because of this problem, Visual Studio 2015 Community Edition would start bashing the CPU (30-40% usage at idle) every time I would open a .cshtml file.
In my case, I recently updated from MVC 4 to MVC 5, which screws up the web.config pretty badly. This article helped tremendously.
http://www.asp.net/mvc/overview/releases/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2
The bottom line is that you need to check all your version number references in your web.config and Views/web.config to make sure that they are referencing the correct upgraded versions associated with MVC 5.
I had the same issue, I created a new project and copied the web.config files as recommended in the answer by Gupta, but that didn't fix things for me. I checked answer by Alex and Liam, I thought this line must have been copied from the new web.config, but it looks like the new project itself didn't have this line (MVC5):
Adding the line to the views/web.config file solved the issue for me.
Changing to @Model from @model did the job for me.
@model represents the View Model object type. @Model represents the View Model object.
Here is what I did:
The .suo file is a hidden file in the same folder as the .svn solution file and contains the Visual Studio User Options.