I have been fumbling around with this problem the entire day, so I decided to ask for some help on here, and hopefully you can help.
I have the following in a view:
@Html.DropDownListFor(model => model.IsProduction, new SelectList(new[]
{
new SelectListItem { Value = "", Text = "Select environment", Selected = true, Disabled = true },
new SelectListItem { Value = "false", Text = "Test" },
new SelectListItem { Value = "true", Text = "Production" }
},
"Value", "Text"),
new { @class = "form-control", @id = "selectEnvironment" })
As you can see, this is a dropdown for a bool with 3 values within the dropdown. The first being what I want to be selected by default (although it is not), and then the values for "true" and "false".
The bool in the model is not nullable, and is not supposed to be nullable. The form will be unable to submit, as long as either "true" or "false" has not been selected.
My question here is: Can anyone see, why it would default to always selecting the "false"-value, although I have defined the ""-value selected by default?
I have tried it without the "Disabled"-attribute, and it changes nothing.
Thanks for any help, that you may be able to give :)