How do I create a ListBox in ASP.NET MVC with single selection mode?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I am assuming you are looking for a select box visually like the ListBox, meaning with multiple rows displayed, but functionally like the DropDownList (allowing for only one selection).
It looks like there is not a particularly easy way to pull this off using ListBox. I’d suggest using Html.DropdownList, similar to this:
The size attribute will give the select box the look of a ListBox. Also, you will need to change your ViewData item from MultiSelectList to SelectList.