Home > asp.net > ASP MVC 5: ViewBag does not exist in the current context

ASP MVC 5: ViewBag does not exist in the current context


After upgrading one of my client’s applications from ASP MVC 4 to ASP MVC 5, We had designers errors related to Html Helpers and ViewBag in cshtml pages.

To fix those issues make sure you do the following:
Install Asp.NET Web Helpers Library from Nuget
Open the Web.config of the project and update the bindings if they haven’t been updated when installing the Nuget packages for example

<dependentAssembly>
<assemblyIdentity name=”System.Web.Mvc” publicKeyToken=”31bf3856ad364e35″ />
<bindingRedirect oldVersion=”0.0.0.0-5.2.2.0″ newVersion=”5.2.2.0” />
</dependentAssembly>

 

Find “webpages:Version” in the appsettings and update it to version 3.0.0.0. My web.config had

<add key=”webpages:Version” value=”2.0.0.0″ />

and I updated it to

<add key=”webpages:Version” value=”3.0.0.0″ />

Restart Visual Studio and rebuild. You may have to delete the bin folder for your project

 

About Lajak Technologies

A consulting firm in Ottawa, Ontario that provides services related to Microsoft technologies, Team Foundation Server, DevOps practices, security and more. Contact us today to help you solving your complex software problems. Visit us at http://www.lajak.com.

Categories: asp.net Tags: ,
  1. February 11, 2015 at 3:35 pm

    Worked for me thanks..

    • Lajak Technologies Inc
      December 4, 2016 at 3:27 pm

      No problem

  2. Ben
    April 6, 2015 at 10:07 am

    Thanks for the fix, that did the trick!

    • Lajak Technologies Inc
      December 4, 2016 at 3:27 pm

      No problem

  1. No trackbacks yet.

Leave a comment