I am trying to make a SelectList
using ViewBag
. But when I run my code it shows where the information I'm trying to access is, for example:
NomeProjeto.Models.NomeModel
I'm using the following code in my Controller
:
var setores = new List<Setor>();
using (RamaDb db = new RamaDb())
{
setores = db.Setores.ToList();
}
ViewBag.ID = new SelectList(setores, "setorNome");
And the one in my View
:
@Html.DropDownListFor(model => model.setores, (IEnumerable<SelectListItem>)ViewBag.ID)
When I run the application on SelectList
, the number of Sectors appears correctly, I have 3 sectors in my DB so 3 options appear, but in all it is written RamalAguia.Models.Setor
How can I fix this?