Search code examples
c#model-view-controllerrazornullreferenceexceptionviewbag

Added new property to ViewBag. Works when ran from Visual Studio, but live version throws Cannot perform runtime binding on a null reference


I have an intranet site where I've added a new property to the ViewBag. When I run in IIS Express via Visual Studio, my changes work fine, but when I updated the actual website (in test) it throws "Cannot perform runtime binding on a null reference"

So I know the ViewBag property that I'm referencing must be null at that point, but I don't see how. I am initializing it in the controller. Here's where the error is being thrown:

@if (ViewBag.FRCP.Count > 0)

Here is where I'm setting the value in the controller:

//Fatal Risk Control Protocols
            List<Documents> FRCPLst = (from x in db.Documents
                                    where x.DocumentTypeId == 29
                                    orderby x.DocumentTitle
                                    select x).ToList();
            ViewBag.FRCP = FRCPLst;

This is in the ActionResult Index() method in the HomeController class, which is an extension of the BaseController class.

I inherited this intranet site from the person that was previously in my role, and I'm very new to MVC so please let me know if more info is required.


Solution

  • Answer comes courtesy of Arturs Mednis. This was a deployment issue. I missed one or more files when deploying my code.