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 trialshawn khah
15,082 Pointscan't solve challenge2 of 2
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 'title', 'description', and 'characters' variables? Restart Preview Get Help Recheck work VideoGamesController.cs Detail.cshtml
1 @{ 2 Layout = null; 3
4 var title = "Super Mario 64"; 5 var description = "Super Mario 64 is a 1996 platform video game developed and published by Nintendo for the Nintendo 64."; 6 var characters = new string[] 7 { 8 "Mario", 9 "Princess Peach", 10 "Bowser", 11 "Toad", 12 "Yoshi" 13 }; 14 } 15 16 <!DOCTYPE html> 17 18 <html> 19 <head> 20 <meta name="viewport" content="width=device-width" /> 21 <title>Video Game Detail</title> 22 </head> 23 <body> 24 <div> 25 <h1>@ViewBag.title</h1> 26
27 <h5>Description:</h5> 28 <div>@ViewBag.description</div> 29
30 <h5>Characters:</h5> 31 <div> 32 <ul> 33 @foreach (var character in ViewBag.Characters) 34 { 35 <li>@character</li> 36 } 37 </ul> 38 </div> 39 </div> 40 </body> 41 </html> 42
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;
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[]
{
"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>@ViewBag.title</h1>
<h5>Description:</h5>
<div>@ViewBag.description</div>
<h5>Characters:</h5>
<div>
<ul>
@foreach (var character in ViewBag.Characters)
{
<li>@character</li>
}
</ul>
</div>
</div>
</body>
</html>
1 Answer
Hannu Shemeikka
16,799 PointsHi,
Your VideoGamesController.cs is fine but you need to remove those variables after "Layout = null;" line. It should work after removing those title, description, and characters variables from Detail.cshtml
shawn khah
15,082 Pointsshawn khah
15,082 Pointsthanks hannu