Clara Mashwama
Clara Mashwama

Reputation: 13

Checkbox wont uncheck

here is my code.

   <div class="form-group">
        <label class="col-md-2 control-label">
            Organizational Units
        </label>
        <div class="col-md-10">
            @foreach (var item in Model.OUList)
            {
                <input type="checkbox" name="selectedOUs" value="@item.Value" checked="@item.Selected" class="checkbox-inline" />
                @Html.Label(item.Text, new { @class = "control-label" })
                <br />
            }
        </div>
    </div>
</div>

this code doesn't allow me to untick if i have selected an org unit. what could be the problem?

Upvotes: 0

Views: 64

Answers (1)

Konstantin Dinev
Konstantin Dinev

Reputation: 34915

The check state of the checkbox is controlled by the existence of the checked attribute, rather than the value inside.

checked="true", checked="asd" and checked="false" will all render the checkbox checked, so rather than binding directly to the Selected value, add the checkbox attribute only when Selected == true.

Upvotes: 1

Related Questions