I have a dropdownlist which is binding with TempData.when it is coming first time it is showing all values.After selecting a particular value that value is saving in the database correctly.But the selected value is not showing.I am giving my code below.
For retrieving I have written in index action controller
TempData["Clients"] = (IEnumerable<SelectListItem>)ClientService.GetALLClientsName().Select(C=>new SelectListItem { Value=C.CLIENT_ID.ToString(),Text=C.CLIENT_NAME});
when retrieving after editing I can not get the selected value.I have written in razor like this below
@if (TempData["SelectedClientName"] != null && TempData["SelectedClientId"] != null)
{
foreach (SelectListItem sli in lstClients)
{
if (sli.Value.Equals(TempData["SelectedClientId"].ToString()))
{
sli.Text = TempData["SelectedClientName"].ToString();
sli.Value = TempData["SelectedClientId"].ToString();
sli.Selected = true;
break;
}
}
}
@Html.DropDownList("drpClientName", lstClients, "--Select--")
I have converted TempData["Clients"] in lstClients.Please help me.