I have a SelectListItem and in an element I put Selected = true, but when passing this object to razor in an @ Html.DropDownList () it does not recognize the selected element.
This is how I have it in my view Razor
@Html.DropDownList("ListaProgramas", (IEnumerable<SelectListItem>)ViewData["ListaProgramas"], new {@class = "form-control pull-left", @id = "ListaProgramas", @style = "color:black; width:100%;" })
List<SelectListItem> listItems = new List<SelectListItem>();
listItems.Add(new SelectListItem
{
Text = row["ProgramName"].ToString().Trim(),
Value = row["Id"].ToString().Trim(),
Selected = valor
});
I put a single element of this list as selected, that is the one I want to appear as selected in razor view.