locked
Viewbag not found RRS feed

  • Question

  • I am using VS2010 Ultimate SP1

    I am recieving an error on my controller that "viewbag" does not exist.

    Reinstalled SP1 didn't fix problem


    this is this
    Sunday, June 5, 2011 2:37 AM

Answers

  • This has nothing to do with VS extensibility, it may have something to do with Razor though I am unfamilar with that.  It looks like you probably have the wrong System.Web.MVC.dll referenced in your project, the 2.0 version of MVC does not have a ViewBag property on the ControllerBase (base class of the Controller class), the 3.0 version does.

    Ryan

    • Marked as answer by Victor_Chen Wednesday, June 15, 2011 7:51 AM
    Tuesday, June 7, 2011 6:27 PM

All replies

  • What do you mean 'on your controller'?  You need to give more context as it is unclear what you are talking about.

    Ryan

    Sunday, June 5, 2011 4:08 PM
  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
     
    namespace newcrest.Controllers
    {
        public class HomeController : Controller
        {
            public ActionResult Index()
            {
                ViewBag.Message = "Welcome to a better search";
     
                return View();
            }
     
            public ActionResult About()
            {
                return View();
            }
        }
    }
    Whilst the above doees not show it my intellisense is puting a red squiggly line under the word ViewBag
    Error 1 The name 'ViewBag' does not exist in the current context D:\Projects\MVC3\newcrest\newcrest\Controllers\HomeController.cs 13 13 newcrest

    this is this
    Tuesday, June 7, 2011 8:12 AM
  • This has nothing to do with VS extensibility, it may have something to do with Razor though I am unfamilar with that.  It looks like you probably have the wrong System.Web.MVC.dll referenced in your project, the 2.0 version of MVC does not have a ViewBag property on the ControllerBase (base class of the Controller class), the 3.0 version does.

    Ryan

    • Marked as answer by Victor_Chen Wednesday, June 15, 2011 7:51 AM
    Tuesday, June 7, 2011 6:27 PM
  • ok that seems reasonable. I'll try that

     

     


    this is this
    Wednesday, June 8, 2011 9:35 AM