views:

242

answers:

2

Are there any html helper methods for displaying boolean values in a dropdown?

+2  A: 

Why not use Html.CheckBox()?

Swingley
Technically you cannot produce null values with a check box. If the semantics of the situation require an "I don't know" possibility, then you need another method. But otherwise this is the right way to go. Or maybe `Html.CheckBox(x => x.Property)`.
NickLarsen
@NickLarsen, Although I agree, the OP specifically asked about bools. And unless it's nullable (not stated), this isn't a problem.
Dan Atkinson
A: 

Use the DropDownListFor helper. Pass in your boolean value and a select list containing values that you want to map back to boolean.

Model.MyBooleanList might be a selectlist with selectlistitems {("Yes",true);("No",false)} Model.MyBoolean is just a bool value that you want to attain/set on your view

<%= Html.DropDownListFor(m => m.MyBoolean, Model.MyBooleanList)%>

hth

kmehta