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?
Changing following line in web.config of view folder solved the same error.
From
To
In my case, I removed web.config file from Views folder by accident. I added it back , and it was OK.
make sure you have the following in both your site web.config and views directory
web.config
in theappSettings
sectionFor MVC5 use:
(And it only exists in the main Web.config file.)
I was trying to add a view which were outside of my "Views" folder (just to organize my code differently, I guess), when I had this issue. Creating the view inside Views (as by convention) solved it.
For some reason my web.config had 0.0.0.0 in the oldVersion attribute:
changing to 1.0.0.0 was the solution:
I think you have messed up the web.config file which lives in the Views folder.
Create a new project targeting the same .NET framework and copy its Views/web.config file on top of the one in your current project. This will fix your problem.
Also, as Dudeman3000 commented, if you have Areas in your MVC project they all have
Views\web.config
files too.