我试过这样做,但这只显示了旁边没有文字的单选按钮.
<% foreach (string s in Html.RadioButtonList("rbl")) {%> <% =s %> <% } %>
Zack Peterso.. 12
Elijah Manor在ASP.NET MVC 1.0中写到了同样的问题:
ASP.NET MVC Html.RadioButtonList Blues
他决定遍历他的DataSource并创建单独的Html.RadioButton和Label组合.
<% var radioButtonList = new SelectList(new List{ new ListItem { Text = "Current", Value="false", Selected=true }, new ListItem { Text = "Other", Value="true"}}, "Value", "Text", "false"); var htmlAttributes = new Dictionary { { "class", "radioButtonList" }, { "onclick", "if(eval(this.value)) { $('#tblDate').show('slow'); } else { $('#tblDate').hide('slow'); }" } }; foreach (var radiobutton in radioButtonList) { %> <%=Html.RadioButton("rblDate", radiobutton.Value, radiobutton.Selected, htmlAttributes)%> <% } %>
ccook.. 8
它曾经在预览中但它被删除了.
如果你在期货中找不到它,请尝试这样的事情
<% foreach (Model model in Models)) { %><%= String.Format("", model.ID, "fieldName", model.modelID, model.Name) %>
<% } %>
brady gaster.. 7
如果是我,我会使用一系列静态HTML元素.我知道有些人会考虑对ASP时间做这样的回归,但它简化了IMO的事情,最终使得更加可靠和可预期[所以我制定了一个词] GUI.
Elijah Manor在ASP.NET MVC 1.0中写到了同样的问题:
ASP.NET MVC Html.RadioButtonList Blues
他决定遍历他的DataSource并创建单独的Html.RadioButton和Label组合.
<% var radioButtonList = new SelectList(new List{ new ListItem { Text = "Current", Value="false", Selected=true }, new ListItem { Text = "Other", Value="true"}}, "Value", "Text", "false"); var htmlAttributes = new Dictionary { { "class", "radioButtonList" }, { "onclick", "if(eval(this.value)) { $('#tblDate').show('slow'); } else { $('#tblDate').hide('slow'); }" } }; foreach (var radiobutton in radioButtonList) { %> <%=Html.RadioButton("rblDate", radiobutton.Value, radiobutton.Selected, htmlAttributes)%> <% } %>
它曾经在预览中但它被删除了.
如果你在期货中找不到它,请尝试这样的事情
<% foreach (Model model in Models)) { %><%= String.Format("", model.ID, "fieldName", model.modelID, model.Name) %>
<% } %>
如果是我,我会使用一系列静态HTML元素.我知道有些人会考虑对ASP时间做这样的回归,但它简化了IMO的事情,最终使得更加可靠和可预期[所以我制定了一个词] GUI.
@{ var radioButtonList = new SelectList(new List{ new ListItem { Text = "1", Value="true", Selected=true }, new ListItem { Text = "2", Value="false"}, new ListItem { Text = "3", Value="false"}, new ListItem { Text = "4", Value="false"}, }, "Value", "Text", "false"); var htmlAttributes = new Dictionary { { "class", "radioButtonList" }, { "onclick", "if(eval(this.value)) { $('#tblDate').show('slow'); } else { $('#tblDate').hide('slow'); }" } }; } @foreach (var radiobutton in radioButtonList) { @Html.RadioButtonFor(m => m.ContactDepartment, @radiobutton.Text) @radiobutton.Text
}