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?
I ran into this problem when I inadvertently had a copy of the view file (About.cshtml) for the route /about in the root directory. (Not the views folder) Once I moved the file out of the root, the problem went away.
I ran into this problem as well. My circumstances were a little different.
One of my view folders was accidentally moved to my project's root directory. This lead to the route
project_root/SignUp/ViewName
matching beforeproject_root/Views/SignUp/ViewName
. This caused the@model
error.After moving the views back into the appropriate location, the directory was somehow recreated in the project root. This time, empty.
/SignUp/ViewName
worked, but/SignUp/
threw a403 - Forbidden: Access is denied.
error. The entire folder must be removed from the project root.I hope this helps someone. I spent hours believing the problem was caused by our recent upgrade from MVC 3 to MVC 4. Just a note: Upgrade problems should only occur between MVC 2 and MVC 3. If you see this problem on later versions, it's probably not due to the upgrade.
Update: If you are using a newer version of MVC, the same process applies, just be sure to use the correct version number in the web.config's
<host>
line.Well, I found myself experiencing the same thing you did, and after a bit further research, I found out what the problem is!
You need to include the default MVC3 web.config for the Views folder. MVC3 has two: one in the root for your application, and one for the views folder. This has a section for included namespaces. Be sure that yours looks something like this:
I suggest that you create a new MVC3 project, then just copy the web.config created for you into your views folder.
Important Once you've done that, you need to close the file and reopen it. Voila! Intellisense!
It took me ages to solve this issue, but finally I hope I have solved it on MVC, that is similar:
I have reinstall ASP.NET 4.5 (http://www.asp.net/downloads)
I have followed the upgrading tutorial on http://www.asp.net/whitepapers/mvc4-release-notes
BUT this mentioned paragraph is wrong for me
Because I have Razor in System.Web.Razor, so I changed the razor namespace to System.Web.Razor.
Add this to your web.config
I have add the assembly reference to all these assemblies above
Locate the ProjectTypeGuids element and replace {E53F8FEA-EAE0-44A6-8774-FFD645390401} with {E3E379DF-F4C6-4180-9B81-6769533ABE47}.
That is all.
I've got the same issue after updating packages. I did the whole stuff You've written above in this topic, but the red underlying of the model keyword has not disappeared. Later, found solution: just deleted 'package' folder from my project's dir and rebuilded, in the meantime allowed NuGet to restore missing packages. Refreshed, and it's done!
Update: 5/5/2015 For your MVC 5 project you need to set the Version to 5.0.0.0 in your /views/web.config