I'm not sure how to handle data received via MultiSelectList
. Also, I can only select more than one option in View
if I press CTRL. Is there a way for the user to click on more than one value without necessarily holding the 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
not Controller
CombosAplicacao bdCombos;
bdCombos = CombosAplicacaoConstrutor.CombosAplicacaoEF();
ViewData["Combos"] = bdCombos.ListarTodos();
Throughout the rest of my application, I work with SelectList
, since I have a relationship usually 1 - n. Only in the case of Combos
I have a many-to-many relationship.
In the case of SelectList
work as follows:
View Create
@Html.DropDownList("Sala", ViewData["Sala"] as SelectList)
Populating with Controller
SalaAplicacao bdSala;
bdSala = SalaAplicacaoConstrutor.SalaAplicacaoEF();
var listSala = new SelectList(bdSala.ListarTodos(), "ID", "Nome");
ViewData["Sala"] = listSala;
Recovering and saving to 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);
}