I am using following code to generate a list box..
<%: Html.ListBoxFor(m => m.Subscribers, new List<SelectListItem>(), new { @class = "list_style_Wizard" })%>
But we can select more than one items from the listbox.. How can i restric it to single select ???
The HTML helpers DropDownListFor
and ListBoxFor
seem to add the multiple
attribute when rendering as a listbox. I use a combination of the DropDownListFor
/ListBoxFor
and a jQuery livequery selector to remove the multiple
attribute. In Razor use:
@Html.DropDownListFor(m => m.SelectedId, Model.SelectList,
new { size = 10, @class = "selectOneListBox" })
and in JavaScript:
$(".selectOneListBox").livequery(function () {
$(this).removeAttr('multiple');
});
I'm sure you could also write your own version of the HTML helper routine that doesn't spit out the multiple
attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With