Wednesday, March 14, 2018

asp.net mvc - Razor View throwing "The name 'model' does not exist in the current context"



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


I know that the usage of @model is correct.



Why is this happening? How can I fix it?


Answer




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.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...