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 Modeling and Presenting Data Using Razor to Render Boolean Values

this question did not make sense to me and I would appreciate some suggestions

Can you give me some suggestions on this question

Detail.cshtml
@model Treehouse.Models.VideoGame

@{
    ViewBag.PageTitle = "Video Game Detail";
}

<h1>@Model.Title</h1>

<h5>Favorite: @Model.Favorite</h5>

<h5>Description:</h5>
<div>@Model.Description</div>

<h5>Characters:</h5>
<div>
    <ul>
        @foreach (var character in Model.Characters)
        {
            <li>@character</li>
        }
    </ul>
</div>
VideoGame.cs
namespace Treehouse.Models
{
    // Don't make any changes to this class!
    public class VideoGame
    {
        public int Id { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public string[] Characters { get; set; }
        public string Publisher { get; set; }
        public bool Favorite { get; set; }

        public string DisplayText
        {
            get
            {
                return Title + " (" + Publisher + ")";
            }
        }
    }
}

3 Answers

Henrique Vignon
PLUS
Henrique Vignon
Courses Plus Student 6,415 Points

It's asking you to run a ternary check on the Favorite property, which is a Boolean, then set the Label "Property: " in the view to say "Yes" in case of true, and "No" in case of false, so it will be something like this:

   <h5>Favorite: @(Model.Favorite ? "Yes" : "No")</h5>

A ternary operation is basically a simplified IF check that runs on a single line, so the check in this case is Model.favorite, since it's a boolean it can either be true of false, the "?" is what tells the interpreter/compiler that this is a ternary check, then whatever comes right after the "?" is what will happen in case that checks pass as true, the ":" is the same thing as an ELSE in a IF, so whatever comes after it is what will happen if the check pass as false.

Henrique Vignon
Henrique Vignon
Courses Plus Student 6,415 Points

ah! someone ninja'ed me :) and with a better explanation at that.

Steven Parker
Steven Parker
231,198 Points

I guess not everyone shares your opinion about the quality of the answers. :stuck_out_tongue_winking_eye:

Steven Parker
Steven Parker
231,198 Points

You're asked to change true or false into "Yes" or "No".

The challenge says to do this with the ternary operator. Do you remember what that is? It uses a question mark and a colon, like this:

/*value or expression to test*/ ? /*value to return if true*/ : /*value to return if false*/

So, to begin with Model.Favorite is either true or false. Your task is to apply a ternary expression to use it to get either the string "Yes" or "No".

thank you everyone I was able to figure this out but I really appreciate the great explanations