Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,157 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