I've tried the following with the List<int>
being always null on the Action:
$('td').delegate('.roleoption select', 'change', function() {
var userRoles = new Array();
$(this).parent().parent().find('select').each(function() {
userRoles.push($(this).val());
});
console.log(userRoles); // [1, 4, 3]
var userId = $(this).parent().parent().parent().find('td').first().text();
console.log(userId); // [2]
$.ajax({
url: '@Url.Action("CambiarRol", "Administracion")',
type: 'POST',
data: { user: userId, roles: userRoles },
success: function(result) {
alert("Worked ok.");
}
});
});
And my Action:
public ActionResult CambiarRol(int user, List<int> roles)
{
// "user" is received correctly. "roles" is null.
return Json(new object());
}
What datatype does my Action need to have in order to correctly receive the roles variable information?
Also what do I need to return from my Action if I want "result" to have a message or something?
success: function(result) {
alert("Worked ok.");
}