参见英文答案 >
How to associate labels with radio buttons4个答案我的表单中有一些选项按钮,我总是需要在圆形选项按钮上完全点击选择它。有没有办法让用户点击相关标签来选择选项按钮?
<p> <span class="editor-label"> @Html.LabelFor(m => m.ADR) </span> <span class="editor-field"> @Html.RadioButtonFor(model => model.ADR,"Yes",AdrYesOptions) @UserResource.YesValue @Html.RadioButtonFor(model => model.ADR,"No",AdrNoOptions) @UserResource.NoValue </span> </p>
我在这里找到了一些解决方案:How to associate labels with radio buttons,但是这些不适合我,因为我更喜欢MVC的特定解决方案。
解决方法
将每个单选按钮和关联的标签文本包含在< label>内。元件:
<p> <span class="editor-label"> @Html.LabelFor(m => m.ADR) </span> <span class="editor-field"> <label> @Html.RadioButtonFor(model => model.ADR,AdrYesOptions) @UserResource.YesValue </label> <label> @Html.RadioButtonFor(model => model.ADR,AdrNoOptions) @UserResource.NoValue </label> </span> </p>