我尝试过这样做,但这只显示了单选按钮,而旁边没有文本。
<% foreach (string s in Html.RadioButtonList("rbl")) {%>
<% =s %>
<% } %> 发布于 2009-04-02 20:22:48
Elijah Manor在ASP.NET MVC1.0中写到了同样的问题:
ASP.NET MVC Html.RadioButtonList Blues
他决定遍历他的DataSource并创建单独的Html.RadioButton和标签组合。
<!-- After using and looking at the code for the Html.RadioButtonList in the ASP.NET MVC 1.0 RTM codebase, I'm not sure how it is supposed to be useful. It only outputs the actual input radio button and doesn't render any corresponding labels. To get around this I ended up writing a foreach creating individual Html.RadioButton and labels -->
<%
var radioButtonList = new SelectList(new List<ListItem> {
new ListItem { Text = "Current", Value="false", Selected=true },
new ListItem { Text = "Other", Value="true"}}, "Value", "Text", "false");
var htmlAttributes = new Dictionary<string, object> {
{ "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)%>
<label><%=radiobutton.Text%></label>
<% } %>发布于 2009-01-04 02:16:36
它曾经在预览中,但它被删除了。
如果你在未来找不到它,试试下面这样的东西
<% foreach (Model model in Models))
{
%><%= String.Format("<input type=\"radio\" value=\"{0}\" name=\"{1}\" id=\"{2}\"><label for=\"{2}\">{3}</label>",
model.ID, "fieldName", model.modelID, model.Name) %><br />
<% } %>发布于 2008-12-09 18:21:42
如果是我,我只会使用一系列静态HTML元素。我知道有些人会考虑回到ASP时代,但它简化了我的工作,最终使它变得更加可靠和可预期,所以我造了一个单词GUI。
https://stackoverflow.com/questions/345396
复制相似问题