RADIOBUTTONLIST IN MVC

Jeet Verma

Total Post:110

Points:776
Posted by  Jeet Verma
 1010  View(s)
Ratings:
Rate this:
I tried doing this but this only display the radiobutton without text beside it.

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

    Post:194

    Points:1396
    Re: RadioButtonList in MVC

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!