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 trialCalvin Secrest
24,815 PointsI think there is a bug with the code challenge or Im missing the synthax?
Challenge Task 2 of 2
Update the Detail.cshtml view to use the ViewBag data. Remove the title, description, and characters variables. Replace the title, description, and characters references with the respective ViewBag properties.
Bummer! Did you remove the 'Layout' property assignment to 'null'?
using System.Web.Mvc;
namespace Treehouse.Controllers
{
public class VideoGamesController : Controller
{
public ActionResult Detail()
{
ViewBag.Title = "Super Mario 64";
ViewBag.Description = "Super Mario 64 is a 1996 platform video game developed and published by Nintendo for the Nintendo 64.";
ViewBag.Characters = new string[]
{
"Mario",
"Princess Peach",
"Bowser",
"Toad",
"Yoshi"
};
return View();
}
}
}
@{
Layout = null;
ViewBag.Title = "Super Mario 64";
ViewBag.Tescription = "Super Mario 64 is a 1996 platform video game developed and published by Nintendo for the Nintendo 64.";
ViewBag.Characters = new string[]
{
"Mario",
"Princess Peach",
"Bowser",
"Toad",
"Yoshi"
};
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Video Game Detail</title>
</head>
<body>
<div>
<h1>@title</h1>
<h5>Description:</h5>
<div>@description</div>
<h5>Characters:</h5>
<div>
<ul>
@foreach (var character in characters)
{
<li>@character</li>
}
</ul>
</div>
</div>
</body>
</html>
2 Answers
Steven Parker
231,198 PointsYou have not completed task 2 yet.
But you have done some other things that confused the checker and it is giving a misleading message.
The first part of task 2 to was "Remove the title, description, and characters variables." You appear to have done this, but you also added a copy of the task 1 code from the controller. That code does not belong here. There should be nothing left in the code block except the assignment of Layout.
The second part of the task is "Replace the title, description, and characters references with the respective ViewBag properties.", and that part still has not been done. It would involve finding the places where the removed variables were being used, and changing them to the proper ViewBag item. For example: "@title
" would change to "@ViewBag.Title
".
curtis allen
28,800 PointsThe Detail.cshtml should have the below code in the top of the html.
@{
Layout = null;
}
Calvin Secrest
24,815 PointsCalvin Secrest
24,815 PointsThank you for assisting me in the challenge but I have another question. When you mention "There should be nothing left in the code block except the assignment of Layout." Are you referring that the entire code block be removed and Layout = null should remain?