Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# ASP.NET MVC Forms Improving Our Form Check Boxes

Calvin Secrest
Calvin Secrest
24,812 Points

Did you add a call to the Html.CheckBoxFor method?

In Report.cshtml update the "Reproducible" field to use a check box. Replace the Html.TextBoxFor method call with a call to the Html.CheckBoxFor HTML helper method. To the right of the Html.CheckBoxFor method call, use the Html.DisplayNameFor HTML helper method to render the display text for the check box.

Need a hint

Report.cshtml
@model IssueReporter.Models.Issue
@using IssueReporter.Models

@{
    ViewBag.Title = "Report an Issue";
}

<h2>@ViewBag.Title</h2>

@using (Html.BeginForm())
{
    <div>
        @Html.LabelFor(m => m.Name)
        @Html.TextBoxFor(m => m.Name)
    </div>

    <div>
        @Html.LabelFor(m => m.Email)
        @Html.TextBoxFor(m => m.Email)
    </div>

    <div>
        @Html.LabelFor(m => m.DepartmentId)
        @Html.DropDownListFor(m => m.DepartmentId, (SelectList)ViewBag.DepartmentsSelectListItems)
    </div>

    <div>
        @Html.LabelFor(m => m.Severity)
        @Html.RadioButtonFor(m => m.Severity,
          Issue.SeverityLevel.Minor) @Issue.SeverityLevel.Minor
        @Html.RadioButtonFor(m => m.Severity,
          Issue.SeverityLevel.Major) @Issue.SeverityLevel.Major
        @Html.RadioButtonFor(m => m.Severity,
          Issue.SeverityLevel.Critical) @Issue.SeverityLevel.Critical
    </div>

    <div>
        @Html.CheckBoxFor(m => m.Reproducible, new {@Html.DisplayNameFor = "Reproducible"})
        @Html.TextBoxFor(m => m.Reproducible)
    </div>

    <div>
        @Html.LabelFor(m => m.DescriptionOfProblem)
        @Html.TextAreaFor(m => m.DescriptionOfProblem)
    </div>

    <button type="submit">Save</button>
}

2 Answers

For others:

<div>
        @Html.CheckBoxFor(m => m.Reproducible) @Html.DisplayNameFor(m => m.Reproducible)

    </div>
Steven Parker
Steven Parker
218,760 Points

:point_right: Here's a few hints to get you back on track:

  • The instructions say "Replace the Html.TextBoxFor method call with a call to the Html.CheckBoxFor", but it looks like you replaced Html.LabelFor instead.
    • Html.CheckBoxFor as used here should take only one argument
    • The Html.DisplayNameFor will be called in a very similar way to Html.CheckBoxFor
    • nothing will be assigned (there won't be any "=")
    • Html.DisplayNameFor replaces Html.LabelFor so the latter will be removed.
Calvin Secrest
Calvin Secrest
24,812 Points

Thanks for the giving me clarity on the challenge.