I have s simple dropdown which is rendered with:
@Html.DropDownListFor(m => m.Request.Value, new SelectList(items, "Value", "Text", selectedElement), new {})
where Model.Request.Value
is of type int
and has the value set to -1.
items
is build like:
var items = new List<SelectListItem<int>>();
items.Add(new SelectListItem<int>{Text = "10", Value = 10});
items.Add(new SelectListItem<int>{Text = "25", Value = 25});
items.Add(new SelectListItem<int>{Text = "100", Value = 100});
items.Add(new SelectListItem<int>{Text = "All", Value = -1});
The value of selectedElement
is 25, which is of type int
. However, it always renders the select with All
selected, which means value = -1.
Why? And why is there a value selectedElement
which get's overridden no matter what?