views:

21

answers:

1

There are loads of questions and answers regarding the issue of posting arrays back to the server using jquery.

However I cant seem to find any solutiion to the problem I'm having. Basically the code below should return an array of ID's back to the server:

I know the array contains items as the length of the array always matches the number of selects that have the option "true" selected

var option = $(".option-select").filter(function () { return $(this).val() == "true"; }).map(function () { return this.id; }).get();
alert(option.length);
$.post("/Quote/GetOptionPrice", { myParam: option }, function (response) { $(".price").html(response); });

This is what is passed to the server:

"myParam[]"

Where am I going wrong?

A: 
var option = $('.option-select').filter(function () { 
    return $(this).val() == "true"; 
}).map(function () { 
    return this.id; 
}).toArray();

$.ajax({
    url: '/Quote/GetOptionPrice',
    type: 'POST',
    data: { myParam: option },
    traditional: true,
    success: function(response) {
        $('.price').html(response);
    }
});
Darin Dimitrov
hi Darin, that still passes "myParam[]" to the server.
StephenLewes
Does setting the `traditional` parameter in the `$.ajax` function make any difference?
Darin Dimitrov
Hi Darin. This passes "myParam" to the server
StephenLewes