0
I would like to insert in the DropDownList
only the sectors that have already been used in contact registration.
In my ContatosController
in the ActionResult
in the method Index
I did this, but the problem that’s happening is that I’m only inserting the last one, so I’ll have to insert it into a new list and then insert this list into the DropDownList
.
I wish I knew the right way
//AQUI ESTOU SEPARANDO EM GRUPOS OS SETORES JÁ UTILIZADOS EM CONTATOS
var setoresEmCadastro = db.Contatos.GroupBy(s => s.SetorId).ToList();
//AQUI PEGO O CÓDIGO DE setoresEmCadastro E PESQUISO
foreach (var item in setoresEmCadastro)
{
var s = db.Setores.Where(a => a.SetorId == item.Key);
//INSIRO NO COMBOBOX
ViewBag.SetorID = new SelectList(s, "SetorId", "Nome");
}