I have the following _ViewStart.cshtml
:
@{
ViewBag.Version = 1;
ViewBag.Debug = false;
}
However, I am getting the following errors:
[ERROR] The name 'ViewBag' does not exist in the current context (@ line 2)
[ERROR] The name 'ViewBag' does not exist in the current context (@ line 3)
[WARNING] ASP.NET runtime error: Could not load file or assembly 'System.Web.Helpers' or one of its dependencies.
I have installed the latest version of ASP.NET MVC (5.2.3) via NuGet.
As you can see, System.Web.Helpers
is referenced.
Also, I have the following page namespaces in my Views/Web.config
:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
Why can't I locate the ViewBag
property and why does that warning shows up?
UPDATE
Using ViewContext.ViewBag
instead of just ViewBag
seems to compile and work. But why is this happening?