我对以下内容感到难过:
这是我的代码:
<div class="editor-field">
<% foreach (string Item in HR_Applications.Helper.GetOrdersForDay(DayOfWeek.Monday))
{ %>
<%= Html.RadioButtonFor(model => model.MondayOrder,Item) %>
<%: Item %>
<br />
<%} %>
</div>
这段代码让我的radiobuttons很好。我在这里遇到的问题是我担心用户不能通过文本选择radiobuttons,但必须单击按钮本身。如何通过文本选择单选按钮?
必须使用此控件:向我提供业务要求。
答案 0 :(得分:1)
设置RadioButton
的ID,并使用label
属性for
。
<label for="<%:Item.Name%>"><%:Item.Name%></label>
<%= Html.RadioButtonFor(model => model.MondayOrder,Item, new {id = Item.Name}) %>
<强>更新强>
如果您无法使用模型中的唯一值作为ID,请使用计数器跟踪并将其附加到您的ID:
<%
int counter = 0;
foreach ( [...])
{
<label for="<%:Item.Name + counter%>"><%:Item.Name%></label>
[...]
counter++;
}
%>