mercredi 31 décembre 2014

Correct Way to Code a Group of Radio Buttons using RadioButtonFor

From what I can see, the correct way to define a checkbox for MVC is as follows.



@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)


This will display a checkbox, associate a label with the checkbox, and make the label clickable, which means clicking the label also toggles the checkbox.


But what happens with RadionButtonFor, where there can be many button/label combinations for the same model field? Using the approach above, there would be multiple elements with the same ID.


I have been researching this for a while now. I have found many solutions; however, they all seem to either not have a clickable label, or they require a bunch of custom and/or non-standard coding.


Did the designers of MVC recognize that we may want to have multiple radio buttons for the same field? And, if so, how is it supposed to be handled?





Aucun commentaire:

Enregistrer un commentaire