Intellisense not working for Razor Views

Donnerstag, 4. Februar 2016

Sometimes when you upgrade ASP.NET MVC (e.g. from 4.0 to 5.x) you encountered following error message:

The name 'ViewBag' does not exist in the current context

Usally this works after verifiying you have these lines in web.config:

<add key="webpages:Version" value="3.0.0.0" />

and

 <dependentAssembly>
 <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
 <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
 </dependentAssembly>
 <dependentAssembly>
 <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
 <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
 </dependentAssembly>
 <dependentAssembly>
 <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
 <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
 </dependentAssembly>