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?
In my case I was missing @ at the beginning of the foreach
In order to solve this I made sure that I upgraded to the newest MVC version using NuGet and Package Manager Console.
Install-Package Microsoft.AspNet.Mvc -Version 5.2.4
Then upgraded to the latest Razor version
Install-Package Microsoft.AspNet.Razor -Version 3.2.4
Then I changed all the web.config files to reflect the change. As you will see below:
In the main web.config file, make sure that the webpages:version is correct. This is where it can be found (ignore the other keys):
Then look for the other versions listed in the assemblies, check the version of the assembly against the version of the library listed in your project references! You may not need all of these.
Runtime assemblyBinding should show the "newversion" as well, see where it reads NewVersion 5.2.4.0? But also check all the other versions.
THEN in the Views Web.Config section, make sure that Razor is the correct version:
And Lastlt there is the Pages section of the Views Web.Config
I've found a solution. If you want to update razor version or mvc 4 to 5, change some lines.
Old code in Views/web.config
Replaced with
sectionGroup
must be change, too.In my case, the following code founds to be useful. Place below code in Web.config file under Views folder.
Once the code is updated, make sure to clean and rebuild the solution. I hope this will help you out!
if you take this problem without any change on your project as like as me, you need change your web.config that placed in View Folder. just write new line by Enter or Remove an empty line . then save your web.config and rebuild. my problem solved with this solution
I solved the problem by using
@Model
instead of justmodel
when printing the variables.