I added a cshtml page in an project. When I tried to add the following declaration to it, I get an error: "The name 'model' does not exist in current context".
@model xyz.abc.SomeClass
I checked the references, all of them are in place. I added a web.config in view folder, but that didn't fix it.
Is there anything i am missing?
Had similar problems using VS2012 and VS2013.
Adding the following line to <appSettings> in the main web.config worked:
If the line was already there but said 2.0.0.0, changing it to 3.0.0.0 worked.
If your views are in a class library assembly, which is useful for reuse of shared views among projects, then just doing what Adam suggests might not be enough. I still had issues even with that.
Try this in your web.config in the root of your project:
And this in the web.config in your views folder:
This worked for me. I now have intellisense and no compile errors on my views in a non-MVC project that I can then reference from multiple MVC websites.
I was missing web.config under Areas/MyArea/Views/web.config. Once added it worked fine. This was with MVC 5 and .NET4.5
Reinstalling the nuget solved it for me
PM> Install-Package Microsoft.AspNet.Razor -Version 3.2.3
While you declare the model at the top of the view using code like this:
you need to capitalise your references to it below, for example:
I believe a missing web.config in the Views folder would be the major cause of this, but if that is fixed and the problem still persists, check that you are using Model, not model to refer to it in the source.
I ran into this same issue when I created an new area to organize my pages. My structure looks kind of like:
WebProject
The views created in the Views folder under the WebProject worked fine, but the views created under the NewArea threw the following error: "The name 'model' does not exist in current context." To fix this I copied the web.config in the Views folder under the WebProject to the Views folder in the NewArea. See below.
WebProject
I ran into this because I manually created this new area using Add -> New Folder to add the folders. I should of right clicked the project and selected Add -> Area. Then Visual Studio would have taken care of setting the area up correctly.