My controller:
[HttpPost]
public ActionResult AddUsers(int projectId, int[] useraccountIds)
{
...
}
I'd like to post the parameters to the controller via AJAX. Passing the int projectId
isn't a problem, but I can't manage to post the int[]
.
My JavaScript code:
function sendForm(projectId, target) {
$.ajax({
traditional: true,
url: target,
type: "POST",
data: { projectId: projectId, useraccountIds: new Array(1, 2, 3) },
success: ajaxOnSuccess,
error: function (jqXHR, exception) {
alert('Error message.');
}
});
}
I tried it with a test array but no success. :(
I also tried to set traditional: true
, or contentType: 'application/json; charset=utf-8'
but no success as well ...
The int[] useraccountIds
posted to my controller is always null.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…