I am trying to pass the ids of the checked boxes to the controller using ajax. Here is the jquery:
function compareEvents() {
var selected = new Array();
$('input:checked').each(function () {
selected.push($(this).attr('id'));
alert("Event " + $(this).attr('id') + " will be compared");
});
$.ajax({
url: "/Event/CompareEvents",
contentType: "application/x-www-form-urlencoded",
type: "POST",
datatype: "json",
data: JSON.stringify({eventIds:selected}),
error: function (xmlHttpRequest, errorText, thrownError) {
alert(xmlHttpRequest, errorText, thrownError);
},
success: function (data) {
alert("success");
document.location = data;
}
});
The alert successfully returns the ids of the checked checkboxes. And returns a success message upon completion.
Here is the controller method:
[HttpPost]
public ActionResult CompareEvents(List<int> eventIds)
{
return null;
}
This gets called successfully, except when i debug, eventIds is returning null. Can anyone see why eventIds is not getting the correct values?