Hi all How can i preselect item in Html.DromDownListFor() ? i have code in view which inserts items to DropDownListFor
<div class="editor-field">
<%var mesta = new List<SelectListItem>();
SelectListItem aa = new SelectListItem();
aa.Text = "---------VYBER MESTO---------";
aa.Value = "0";
mesta.Add(aa);
foreach (var item in Model.MestoTbl)
{
SelectListItem a = new SelectListItem();
a.Text = item.Mesto;
a.Value = item.MestoId.ToString();
mesta.Add(a);}%>
<%: Html.DropDownListFor(model => model.Mesto.MestoId, mesta)%>
<%: Html.ValidationMessageFor(model => model.Mesto.MestoId)%>
</div>
this inserts 2 values MestoId & Mesto ....when i click on some database record (edit field) example =>
Name Surname Mesto
--------------------
Peter Malik Snina
Snina => Mestoid = 2 I wanna get .... if i click to edit record of Peter Malik the Html.DropDownListFor automatically preselect item Snina in list.