I have the selected code of a property in a model and the descripcion in another one, i'm trying to show in my view the description, not the code, i am populating the list from a diferent database table and trying to set the selected value from the model used in the view.
This is my View
IEnumerable<SelectListItem> listaMotivos = (IEnumerable<SelectListItem>)ViewBag.motivosFinalizacion;
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Win_User_ID)
</td>
<td>
@Html.DropDownListFor(modelItem => item.Motivo_Finalizacion, listaMotivos, "", htmlAttributes: new { @class = "form-control", @id = "IndexSalarioVendedor" })
</td>
</tr>
}
My list is populate in the controller by:
public void cargarMotivosFinalizacion()
{
ViewBag.motivosFinalizacion = db.SFI_AtributosDbSet.Where
(x => x.Tipo_Atributo == "MOTIVO FINALIZACION").OrderBy(x =>
x.Descrip_Atributo).Select(x => new SelectListItem
{
Text = x.Descrip_Atributo,
Value = x.ID_Atributo
}).ToList();
}
I need to set the code selected in the dropdownlist from model but is not working