AJAX:
function systemsChanged(elem)
{
var items = [];
for (i = 0; i < elem.length; i++)
if (elem[i].selected) {
items.push(elem[i].value);
}
var post = { ids: items };
$.ajax({
type: "POST",
traditional: true,
url: "@Url.Action("LoadApplicationConfigs", "Application")",
content: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify(post),
success: function (d) {
alert(d.message);
},
error: function (xhr, textStatus, errorThrown) {
alert("não rolo");
}
});
}
C# MVC 4:
[HttpPost]
public JsonResult LoadApplicationConfigs(IList<string> ids)
{
object data = new
{
message = "aha!"
};
return new JsonResult() { Data = data };
}
It enters the post method but ids is set to null. I also tried changing ids to string[], not successfully. The return to ajax is fine: it shows the "aha!" alert. I just cant seem to be providing the accurate format to the mvc binder. Any thoughts?
IEnumerable<string>IEnumerable<string>didnt work either