When viewing my selections, I have several drop-down lists that display the ID and I would like the name to be shown to the user for clarity. However, when I list everything that has been added, it displays the chosen ID instead of the name.
I attempted to resolve this by using the code below, but it always displays the status with the ID 1, which is "Active."
@Html.DropDownListFor(modelItem => item.status,
(SelectList)ViewBag.listStatus,
new { @class disabled = "" })
//controller
{
public ActionResult listStatus()
{
var list= ListsDAO.listStatus();
return View(list);
}
}
//DAO
{
public static IEnumerable<LISTS> listStatus()
{
using (var ctx = new PadraoEntities())
{
var result= from lists in ctx.LISTS
where lists.TYPE_LIST== "STATUS"
select new
{
lists.IDE_LIST,
lists.DES_LIST,
lists.VLR_LIST
};
var list= new List<LISTS>();
foreach (var item in result)
{
list.Add(new LISTS()
{
IDE_LIST = item.IDE_LIST,
VLR_LIST = item.VLR_LIST,
DES_LIST = item.DES_LIST
});
}
return list;
}
}
}
//view add
<div class="form-group">
@Html.LabelFor(model => model.status, htmlAttributes: new { @class = "control -Label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.status(SelectList)ViewBag.listStatus, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.status, "", new { @class = "text-danger" })
</div>
</div>
//view list
{
@Html.DropDownListFor(modelItem => item.ststus,(SelectList)ViewBag.listStatus,new { disabled = "" })
}
Instead of displaying the IDs when listing, I expected "Active" to appear for ID 1, "Inactive" for ID 2, and so on.