0

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?

1
  • Try using FireBug and see as what data is being sent. Ensure that the data is in format that can be mapped into int[] array. Commented Nov 3, 2011 at 16:51

1 Answer 1

4

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 .each

Check this similar question: Post array of multiple checkbox values

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. This solved my problem. var checkedItems = $('*[id*=lead]:checked').map(function (i, n) { return $(n).val(); }).get();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.