0

I have razor view with checkbox. I cant able to prepopulate checkbox with true/false . Here is my code

<label for="HousingBidsComps_99">&nbsp;</label>
<div class="check_box_group">
    <input type="checkbox" id="HousingBidsComps_99" name="HousingBidsComps[1].IsChargesIncluded" class="customCheckbox"  >
    <label for="HousingBidsComps_99" style="margin-bottom:0">
        <span style="margin-bottom:0">
            @Html.LabelFor(model => model.HousingBidsComps[1].IsChargesIncluded, new { @class = "padd-left-0" })
        </span>
    </label>
</div> 
Sujatha
  • 182
  • 2
  • 13
  • Use `@Html.CheckBoxFor(m => m.HousingBidsComps[1].IsChargesIncluded)` - always use the `HtmlHelper` methods to bind to your model –  Nov 24 '17 at 07:15
  • And your two ` –  Nov 24 '17 at 07:21

1 Answers1

2

You should try to bind your checkbox like this:

<label for="HousingBidsComps_99">&nbsp;</label>
<div class="check_box_group">

  @Html.CheckBoxFor(m => m.HousingBidsComps[1].IsChargesIncluded, new { @class="customCheckbox" })

    <label for="HousingBidsComps_99" style="margin-bottom:0">
        <span style="margin-bottom:0">
            @Html.LabelFor(model => model.HousingBidsComps[1].IsChargesIncluded, new { @class = "padd-left-0" })
        </span>
    </label>
</div> 
Vishvadeep singh
  • 1,624
  • 1
  • 19
  • 31
  • You DO NOT set the `checked` attribute in the `CheckBoxFor()` method! (its ignored fortunately since that would make the checkbox always checked even if the property value was `false`) –  Nov 24 '17 at 08:18