I have a dropdownlistfor
:
@Html.DropDownListFor(model => model.Item.Item.Status, new SelectList(@Model.AllStatus, \"id\", \"Description\"),
There exist already some discussions about that here or there. One of the problems might be using a different type than string
for the key value. I had similar problems in past and I know that i solved it like this - explicitly setting the Selected
property when preparing the list (in your case, AlLStatus
).
Would mean, for your case (in controller action):
IEnumerable selectList =
from s in allStatus // where ever you get this from, database etc.
select new SelectListItem
{
Selected = (s.id == model.Item.Item.Status),
Text = cs.Description,
Value = s.id.ToString()
};
model.AllStatus = selectList;