Search code examples
asp.netasp.net-mvc-3webformsviewbag

'ViewBag' is not declared. It may be inaccessible due to its protection level


I've integrated ASP.NET MVC 3 project into existing Web Forms project. It was working fine, without any error. We have multiple developers working on a project using SVN source control.

MVC3 was integrated in my machine, but when other developers updates project to the latest version, it is not working on their machine.

The only problem is 'ViewBag' is not declared. It may be inaccessible due to its protection level.

Here is a part of the code.

Public Class NewsletterMController
Inherits Controller
Protected Overrides Sub OnActionExecuting(ByVal filterContext As System.Web.Mvc.ActionExecutingContext)
    ViewBag.CurrentUser = Membership.GetUser()
    MyBase.OnActionExecuting(filterContext)
End Sub

End Class

As you see, I've inherited "Controller" Also, I've Imported System.Web.Mvc & System.Web.Abstractions & System.Web.Routing. In addition, references is well done, and assemblies are registered in Web.config

Anyone has an idea? Why I can't access ViewBag from Web Forms?


Solution

  • The ViewBag property is introduced in MVC3. Make sure that you are using the correct version of the System.Web.Mvc on all machines.