Reputation: 9416
<td>
@if (ViewBag.MyList as System.Collections.IEnumerable != null)
{
int i = 1;
foreach (var m in new SelectList(ViewBag.MyList as System.Collections.IEnumerable, "Value", "Text", 0))
{
@Html.RadioButton("MyList" + i, m.value)
@Html.Label(m.Text)
i += 1;
}
}
</td>
If i have code similar to the above in an ASP.NET MVC view, how do I get the value of the selected RadioButton in jQuery? Some thing along the line $.trim($("#MyList").val())
doesn't seem right as #MyList (i.e name of the drop-down will be dynamic depending on the value of variable i)
Upvotes: 0
Views: 1386
Reputation: 56688
jQuery has "starts with" selector for such case. To get the selected item, use "checked":
var v = $.trim($("[id^='MyList']:checked").val());
Upvotes: 1