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 Displaying a List of Values

I am frustrated and confused

I have duplicated as best as I understand, the code displayed in Displaying a list with Rasor Any suggestions as to what i AM DOING WRONG AND OR NOT UNDERSTANDING WOULD BE APPRECIATED

Detail.cshtml
@{
    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",03:0403:04
04:16


04:16


        "Yoshi"03:04
04:16


    };
}

<!DOCTYPE html>

<html>03:04
04:16


<head>
    <meta name="viewport" content="width=device-width" />03:04
04:16
03:04
04:16



    <title>Video Game Detail</title>
</head>
<body>
    <div>
        <h1>@title</h1>

        <h5>Description:</h5>
        <div>@html.Raw(description)</div>

      @if (character.length > 0)
      {        
        <h5>Characters:</h5>
        <div>
            <ul>
                @foreach (var character in characters)
              {
              <li>@character</li>
              }
            </ul>
        </div>
      }
    </div>
</body>
</html>

When you are learning something new and you think you can't do it. It is normal start from beginning and different way. When you get it on your own it helps you more.

1 Answer

Hello, you probably wanted to check if array of characters has length greater than zero, but you have character. However,you do not need to check it, if array exists and has length 0 loop does not start. Everything else should be good. I did it like this:

@foreach (string character in characters)
{
     <li>@character</li>
}