I need to get an array of select and send to a function in the controller, but it always arrives as null, even sending the complete array. Here is the code: Controller:
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult GetLocais(int [] idcTipoLocal)
{
var local = context.Locais.Where(x => x.IdcSite == ContextSession.UsuarioLogado.IdcSite && x.Status /*&& x.IdcTipoLocal == idcTipoLocal*/).Distinct()
.Select(x => new { id = x.IdcLocal, text = x.Nome }).OrderBy(y => y.text).ToList();
return Json(local, JsonRequestBehavior.AllowGet);
}
JavaScript:
var opt = new Array();
$("#selTipLocal").change(function () {
var obj = [];
$('#selTipLocal > option:selected').each(
function (i) {
opt[i] = $(this).val();
opt[i] = parseInt(opt[i]);
});
var jsonKey = {
"idcTipoLocal": opt
};
$.get("/relocorrencia/getlocais", jsonKey, function (data) {
$("#selLocal").multiselect("destroy");
multiSelectRelOco("selLocal", data);
});
});
I already checked and the arrey arrives ok, but when sending to the controler, idctipolocal always arrives as null