Fix for "ViewBag" does not exist in current context within Razor MVC App

We may get below error, while browsing Razor MVC 3 application:

Untitled.png

To fix it, follow below steps:

1. Verify you have latest version of MVC 3 [It may be Beta or pre-release version] or not.

2. If not, update the MVC 3 by using Web Platform Installer or installing AspNetMVC3ToolsUpdateSetup.exe from http://www.asp.net/mvc/mvc3.

3. If issue still exist, add a reference or copy System.Web.Webpages.RazorSystem.Web.Webpages.Razor.dll  [present in
C:\Program Files\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\] to App's bin folder and try.

4. If it won't help, re-install MVC 3 completely.


Next Recommended Reading ViewData VS ViewBag Vs TempData in MVC