mercredi 13 avril 2016

Cannot make checkbox work

I have the following code:

 <div class="checkbox checkbox-primary">  
     @Html.LabelFor(p => p.Confirm)
     @Html.CheckBoxFor(p => p.Confirm)
 </div>

It shows the bootstrap styled checkbox but i cannot check it, when i click nothing happens.

But if i do:

<div class="checkbox checkbox-primary">
   <input id="Confirm" type="checkbox">
        <label for="Confirm">
           Confirm
        </label>
 </div>

It works as expected.

The model property:

   public bool Confirm { get; set; }

Whats wrong here? If i put the razor code outside the <div class="checkbox checkbox-primary"> it works too.

EDIT: Generated code:

<div class="checkbox checkbox-primary">                                               
   <label for="Confirm">Confirm</label>
   <input data-val="true" data-val-required="Field is required" id="Confirm" name="Confirm" type="checkbox" value="true">
   <input name="Confirm" type="hidden" value="false">
</div>




Aucun commentaire:

Enregistrer un commentaire