0

I have a dropdown in which i was able to get/set the selected value when the property is string, but when it is bool i couldn't able to get/set the value.

//Code:

 <div class="editor-field"> 
            @Html.DropDownListFor(model => model.SelectedStatus, Model.SelectedStatusList(), "--Select--")
             @Html.ValidationMessageFor(x => x.SelectedStatus, "Field is required")
        </div>

How can i achieve this?

A Coder
  • 3,039
  • 7
  • 58
  • 129

2 Answers2

1

Dropdowns are used when the domain of the property accept multiple answers, like, what's the color of John's hair? It might be blue, it might be black, white, yellow, etc.

When the property accepts only true or false it's better to use a checkbox.

Check this answer to learn on how to deal with checkboxes and auto-bindings.

Community
  • 1
  • 1
Anderson Fortaleza
  • 2,449
  • 20
  • 22
1

Have you try to set the value as 0 and 1 instead true and false? that might be the reason its not being parsed properly

qamar
  • 1,437
  • 1
  • 9
  • 12
  • Good idea. But i need to know is there any solution for the above query. – A Coder May 11 '14 at 14:17
  • well, if you look at this way then you need do some javascript code to convert true to 1 or false to 0 prior form submission. I prefer to do it with direc 0 and 1 – qamar May 11 '14 at 14:19