Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# ASP.NET MVC Basics Views Setting Data in the Controller

Got an error with the ViewBag.Artist

Server Error in '/' Application. Cannot perform runtime binding on a null reference Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference

Source Error:

Line 19: <div>@Html.Raw(ViewBag.Description)</div> Line 20: Line 21: @if (ViewBag.Artists.Length > 0) Line 22: { Line 23: <h5>Artists:</h5>

This exception is thrown at line 21. It's not misspelled: (ComicBooksController.cs)

        ViewBag.Artists = new string[]
        {
            "Script: Dan Slott",
            "Pencils: Humberto Ramos",
            "Inks: Victor Olazaba",
            "Colors: Edgar Delgado",
            "Letters: Chris Eliopoulos"
        };

Please help!

2 Answers

Robert Stefanic
Robert Stefanic
35,170 Points

Where within the ComicBooksController are you assigning your new string[]?

Could you post the function where you've assigned ViewBag.Artists to your string[]?

I needed to restart the browser and all went fine, thx for your help m8