1
I’m not sure how to handle the received data via MultiSelectList
. Also, I can only select more than one option on View
if I press CTRL. There is a way the user can click more than one value without necessarily holding this key?
View Create
<div>
Combos @Html.ListBox("Combos", new MultiSelectList(ViewData["Combos"] as System.Collections.IEnumerable, "id", "nome", Model.Combos.Select(x => x.id).AsEnumerable()))
</div>
Populating MultiSelectList
in the Controller
CombosAplicacao bdCombos;
bdCombos = CombosAplicacaoConstrutor.CombosAplicacaoEF();
ViewData["Combos"] = bdCombos.ListarTodos();
Throughout the rest of my application, I work with SelectList
, because I have a normal relationship of 1 - n. Only in the case of Combos
that I have a relationship of many to many.
In the case of SelectList
work as follows:
View Create
@Html.DropDownList("Sala", ViewData["Sala"] as SelectList)
Populating Controller
SalaAplicacao bdSala;
bdSala = SalaAplicacaoConstrutor.SalaAplicacaoEF();
var listSala = new SelectList(bdSala.ListarTodos(), "ID", "Nome");
ViewData["Sala"] = listSala;
Retrieving and saving in the bank by Controller
[AcceptVerbs(HttpVerbs.Post)]
public PartialViewResult Create(CONGRESSO_Cursos cursos, FormCollection dados)
{
SalaAplicacao bdSala;
bdSala = SalaAplicacaoConstrutor.SalaAplicacaoEF();
cursos.CONGRESSO_Sala = bdSala.ListarPorId(dados["Sala"]);
bdcursos.Salvar(cursos);
}