MVC和放大器;单选按钮列表 [英] MVC & RadioButtonList

查看:115
本文介绍了MVC和放大器;单选按钮列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图这样做,但这种只显示它旁边没有文字的单选按钮。

 <%的foreach(字符串s在Html.RadioButtonList(RBL)){%GT;
    <%= S%GT;
<%}%GT;


解决方案

利亚庄园写同样的烦恼在ASP.NET MVC 1.0:

ASP.NET MVC Html.RadioButtonList蓝调

他通过他的DataSource决定环路,并创建个人Html.RadioButton和标签组合。

 <! - 使用来看,在code在ASP.NET MVC 1.0 RTM codeBase包括Html.RadioButtonList后,我不知道它是如何应该是有用的。它只输出的实际输入单选按钮,并没有提供任何相应的标签。为了解决这个问题我最后写一个foreach创建单个Html.RadioButton和标签 - >
<%
VAR单选按钮列表=新的SelectList(新名单<&列表项GT; {
    新的ListItem的{text =电流,值=假,选择= TRUE},
    新的ListItem的{text =其他,值=真},值,文本,假);
VAR htmlAttributes =新词典<字符串对象> {
    {类,单选按钮列表},
    {onclick事件,如果(EVAL(THIS.VALUE)){$('#tblDate)节目(慢);}其他{$('#tblDate')隐藏('慢');} }
};
的foreach(在RadioButtonList的VAR单选){%GT;
    &所述;%= Html.RadioButton(rblDate,radiobutton.Value,radiobutton.Selected,htmlAttributes)%GT;
    <标签><%= radiobutton.Text%GT;< /标签>
<%}%GT;

I tried doing this but this only display the radiobutton without text beside it..

<% foreach (string s in Html.RadioButtonList("rbl")) {%>
    <% =s %>
<% } %> 

解决方案

Elijah Manor wrote about the same trouble in ASP.NET MVC 1.0:

ASP.NET MVC Html.RadioButtonList Blues

He decided to loop through his DataSource and create individual Html.RadioButton and Label combinations.

<!-- 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>
<% } %>

这篇关于MVC和放大器;单选按钮列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆