I’m having some problems passing an integer array to an MVC controller.
I’m grabbing my values as follows:
$checkedItems = $(':checked');
My ajax post is formatted like this:
$.ajax({
url: '/Items/MarkUnsuitable',
type: 'POST',
traditional: true,
data: { checkedRecords: $checkedItems, deletionReason: reason, deletionDescription: description },
error: function (xhr, ajaxOptions, thrownError) {
alert('An error occured when processing this request:\r\n\r\n' + thrownError);
},
My controller is receiving the data like this. The only missing value is the int[]
public ActionResult MarkUnsuitable(int[] checkedRecords, int? deletionReason, string deletionDescription)
Could anybody assist me with this problem?
Have you used Firebug to inspect the data that’s being posted yet? If not, that would help. My suspicion is that you don’t have a “value” attribute on the checkboxes so you’re just posting names with no value.
You might want to build an array manually using
.eachCheck this similar question: Post array of multiple checkbox values