Home > DeveloperSection > Forums > RadioButtonList in MVC
Jeet Verma
Jeet Verma

Total Post:110

Points:776
Posted on    October-08-2014 12:09 AM

 ASP.NET MVC ASP.Net  ASP.NET MVC 
Ratings:


 1 Reply(s)
 695  View(s)
Rate this:
I tried doing this but this only display the radiobutton without text beside it.

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


Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Posted on    October-08-2014 12:11 AM

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

Don't want to miss updates? Please click the below button!

Follow MindStick