C# Razor EditorFor Checkbox coché par defaut

Résolu/Fermé
clem285 Messages postés 281 Date d'inscription samedi 29 septembre 2007 Statut Membre Dernière intervention 22 octobre 2021 - 13 juil. 2016 à 12:54
clem285 Messages postés 281 Date d'inscription samedi 29 septembre 2007 Statut Membre Dernière intervention 22 octobre 2021 - 15 juil. 2016 à 08:54
Bonjour à tous !

J'aimerai avec Razor avoir une checkbox cochée par défaut dans mon formulaire.

Comment faire ?

<div class="form-group">
@Html.LabelFor(model => model.actif, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<div class="checkbox">
@Html.EditorFor(model => model.actif)
@Html.ValidationMessageFor(model => model.actif, "", new { @class = "text-danger" })
</div>
</div>
</div>



j'ai essayé plusieurs chose telle que :

@Html.EditorFor(model => model.actif, new { @checked="checked" })

@Html.EditorFor(model => model.actif, new { @checked="true" })

@Html.EditorFor(model => model.actif, true)


mais rien ne fonctionne :(

1 réponse

clem285 Messages postés 281 Date d'inscription samedi 29 septembre 2007 Statut Membre Dernière intervention 22 octobre 2021 83
15 juil. 2016 à 08:54
au final, j'ai fait comme ça :

<div class="form-group">
@Html.LabelFor(model => model.actif, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.CheckBoxFor(model => model.actif, new { @class = "form-control", @checked ="checked"})
@Html.ValidationMessageFor(model => model.CB2500, "", new { @class = "text-danger" })
</div>
</div>
0