jeudi 12 mars 2020

Set Label for checkbox using razor by appliying helper html.DisplayName to html.CheckBox

I am trying to associate a label to a checkbox using Razor helpers:

<div class="checkbox">
    <label>@Html.CheckBox("MyLabel", true)&nbsp;@Html.DisplayName("Check/UnCheck this")</label>
</div>

similar as explained here in the answer by @Jess.

Label and checkbox is displayed correctly in the view. My question is, in this scenario, when using Razor helper Html.CheckBox (Not Html.CheckBoxFor), is it the correct way to associate the label to the checkbox?




Aucun commentaire:

Enregistrer un commentaire