mercredi 24 août 2016

Pass boolean value by checkbox

I would like to pass my bool value by checkbox.

Here's my property

  public bool MyBooleanValue{ get; set; } = true;

and here;s my HTML:

<input type="checkbox" id="@nameof(Model.MyBooleanValue)" name="my-boolean" value="1" class="" checked="checked" />

<label for="@nameof(Model.MyBooleanValue)">some text</label>

<input type="hidden" name="my-boolean" value="true" />

In default I would like to have checked field. What's wrong with this code ? I use ASP.NET MVC 5.




Aucun commentaire:

Enregistrer un commentaire