1
In a CMS I own a DropDownList
and a ListBox
that work regularly in the field of registration, however, do not bring values in the field of editing.
View
<div>
Tipo de Curso<br />
@Html.DropDownList("TipoCurso", ViewData["listTipoCurso"] as SelectList)
</div>
<div>
Promoções <br />
@Html.ListBox("Promocoes",
new MultiSelectList(ViewData["Promocoes"] as System.Collections.IEnumerable,
"id", "nome"), new
{
@class = "chosen-select",
@placeholder = "Escolha uma Opção"
})
</div>
Controller
TipoCursoAplicacao bdTipoCurso;
bdTipoCurso = TipoCursoAplicacaoConstrutor.TipoCursoAplicacaoEF();
var listTipoCurso = new SelectList(bdTipoCurso.ListarTodos()
.GroupBy(x => x.Nome.ToLower().Trim()).Select(y => y.First()),
"ID", "Nome");
ViewData["listTipoCurso"] = listTipoCurso;
PromocoesAplicacao bdPromocoes;
bdPromocoes = PromocoesAplicacaoConstrutor.PromocoesAplicacaoEF();
ViewData["Promocoes"] = bdPromocoes.ListarTodos();
How could you proceed to bring selected data registered in Listbox and in the Dropdownlist at editing time?
The problem is that Typocurso and Promocoes are foreign keys and my View is typed for Courses
– Rafael Barbosa
It worked. Thank you.
– Rafael Barbosa