Visual Studio and MVC is very keen for you to use Nuget packages to easily update the libraries your site is using.
Alas it usually makes a bit of a mess of things. Upgrading from MVC4 to MVC5 can really mess up your intellisense so nothing in Razor is recognised. The application still compiles and runs but it is a pain in the arse if you want to do any code changes.
The problem is caused by the version numbers of the libraries. When you update MVC to a newer version it isn’t clever enough to update the version numbers of the libraries in the web.config files.
To fix this you need to go looking in the View folder for the “other” web.config that is used for razor views. This is full of references to MVC and Razor dlls with version numbers that don’t get updated when your project does. The best way to check they are the correct versions is to look in the references for your project and click on each reference that is listed in the web.config. The correct version will be shown in the properties pane and you can simply type it into the correct place in the web.config. The example below is for an MVC 188.8.131.52 project. I have underlined the versions to change. If you upgraded from MVC4 these will still say 4.x.x.x.
Save the config file and then go to the main web.config file for one more version to change. In the appsettings area there should be a setting called webpages:version. This also needs to be set to the correct version for razor. e.g. 184.108.40.206. You will probably find it is set at 220.127.116.11.
Save all the changes, reload visual studio, do a clean and rebuild and all the nasty red underlines should have gone away.
Waaahh the red squiggly lines still haven’t gone away!!!
Couple more things to try. First thing is to close Visual Studio and hunt down your website’s temporary files in C:\Windows\Microsoft.Net\Framework and Framework64. There will be a folder called “Temporary ASP.NET Files” in v4.0.30319 of the framework. Delete everything in here. This will force a rebuild of your websites.
Next one is to clear out Visual Studio’s own cache. Go to C:\Users\your username\AppData\
Restart Visual Studio and give it a few minutes to rebuild it’s cache and everything should work. If not you are on your own.