Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "CS0103: The name 'ViewBag' does not exist in the current context" when deploying MVC3 remotely

I know this error has been posted elsewhere, but the solutions provided don't work for me.

Background:

  • I created a brand new project using MVC3 with Razor syntax using Visual Studio 2010 SP1.
  • Everything works fine when I run the project locally.
  • I installed MVC3 on my remote server and deployed the project.

I get the following error:

Compiler Error Message: CS0103: The name 'ViewBag' does not exist in the current context
Source Error:
Line 1:  @model MyModels.AModel
Line 2:  @{
Line 3:      ViewBag.Title = "Home Page";
Line 4:  }
Line 5:  <script type="text/javascript">
  • I checked, and I do have a Web.Config file in my Views directory that appears to be complete.
  • This is not an upgraded solution. I did not go from a previous MVC beta to the final release.
  • I'm going crazy at this point. I'll be happy to provide more information if requested.
like image 459
Jim Avatar asked Mar 26 '12 16:03

Jim


1 Answers

Argh. The server where I had deployed my app to had an old version of MVC3. I had ran the MVC3 installer prior to deploying my app, but apparently the installer does not remove previous beta or RC versions of MVC3. You must uninstall previous versions of MVC3 via add/remove programs prior to installing the newer version.

I was able to make this work in two ways:

  1. Uninstall MVC3 completely from the server, then bin deploy the MVC3 dlls with my app.
  2. After uninstalling MVC3 completely, install the latest version from http://www.microsoft.com/web/gallery/install.aspx?appid=MVC3

Note: Restart IIS after any changes. (Recycling just the app pool would probably work, too.)

like image 50
Jim Avatar answered Sep 23 '22 22:09

Jim