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 Using ViewBag

I am very confused on this question - ASP.NET basics question

I am not sure what to do. I have been examining the question for a long time now. I could use a few suggestions.

using System.Web.Mvc;

namespace Treehouse.Controllers
    public class VideoGamesController : Controller
        public ActionResult Detail()
            return View();
    Layout = null;

    var title = "Super Mario 64";
    var description = "Super Mario 64 is a 1996 platform video game developed and published by Nintendo for the Nintendo 64.";
    var characters = new string[]
        "Princess Peach",

<!DOCTYPE html>

    <meta name="viewport" content="width=device-width" />
    <title>Video Game Detail</title>


                @foreach (var character in characters)

2 Answers

James Churchill
James Churchill
Treehouse Teacher


Sorry to hear that you're struggling with this code challenge. There are two parts to this challenge:

1) For the first task, you'll move the title, description, and characters variable values to the controller Detail action method. To do that, you'll need to define properties on the ViewBag object. For instance, you'll set a ViewBag.Title property value to the value "Super Mario 64".

2) For the second task, you'll remove the title, description, and characters variables from the Detail.cshtml view and replace any references to those variables with the respective ViewBag properties. For instance, remove the title variable and update the "<h1>" element content to be "@ViewBag.Title".

Hopefully this helps clarify the challenge a bit. Please let me know how it goes.

Thanks ~James

Thank you. I did work through this and got an answer. I appreciate all the people who helped with my questions