So, I am trying to pass the chosen multiselect values throught a DropDownList and a BeginForm. Don't want to pass with javascript/ajax. The chosen plugin is working fine, show me the entries like i want. But I'm getting null values on controller:
Model
public class SorteioEspecial
{
RepositoryService service = new RepositoryService();
public SorteioEspecial()
{
funcionario = new List<Funcionario>();
ponderacaoFuncionario = new List<PonderacaoFuncionario>();
SelectedIds = new List<int>();
}
public int Id { get; set; }
public IEnumerable<Funcionario> funcionario { get; set; }
public IEnumerable<PonderacaoFuncionario> ponderacaoFuncionario { get; set; }
public List<int> SelectedIds { get; set; }
public IEnumerable<Funcionario> GetFuncionarios()
{
funcionario = service.GetFuncionarios();
return funcionario;
}
public IEnumerable<PonderacaoFuncionario> GetPonderacaoFuncionario()
{
ponderacaoFuncionario = service.GetPonderacaoFuncionario();
return ponderacaoFuncionario;
}
}
Controller
[HttpGet]
public ActionResult EscolherFuncionarios()
{
var sorteioEspecial = new SorteioEspecial();
List<Funcionario> list = new List<Funcionario>();
list = sorteioEspecial.GetFuncionarios().ToList().OrderBy(x => x.Nome).ToList();
ViewBag.FuncionarioId = new SelectList(list, "Id", "Nome");
return View(sorteioEspecial);
}
[HttpPost]
public ActionResult EscolherFuncionarios(List<int> SelectedIds)
{
return View();
}
View
@model Apdd.Models.SorteioEspecial
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Escolha os funcionários a ir a sorteio</h2>
@using (Html.BeginForm())
{
@Html.DropDownList("FuncionarioId", null, htmlAttributes: new { @class = "chosen-select", @data_placeholder = "Pick one!", @multiple = "true" })
<input type="submit" value="save" />
}
<script src="~/Scripts/jquery-2.1.1.js"></script>
<script src="~/Scripts/jquery.js"></script>
<script src="~/Scripts/chosen.proto.js"></script>
<link href="~/Scripts/chosen.css" rel="stylesheet" />
<script src="~/Scripts/chosen.jquery.js"></script>
<script>
$(".chosen-select").chosen({
disable_search_threshold: 10,
no_results_text: "None!",
width: "95%"
});
</script>
The values in the ViewBag are a list of entities (Id, Name, and some more parameters), and for what I have been seing, the chose only passes the Id, exactly What I want. What I have to do to pass the values to controller?