user1765862
user1765862

Reputation: 14145

sending data from js to the mvc controller

I have on the view list of images with checkbox in front each image. Checkbox is populated with image id so I can recognize which image is checked for manipulation.

When button is clicked I'm recognizing which images are checked and store each image id to the array of ints. These array I want to sent to the mvc3 controller but I have problem I'm getting error inside sent parameters (firebug). For example if two images are checked I got following:

undefined   undefined
undefined   undefined

here's the code

var imgList = [];
$('#deleteImgBtn').click(function () {
    $('.imgCheckbox:checked').each(function () {      
        var id = $(this).attr('id');
        imgList.push(id);
    });
    jQuery.ajaxSettings.traditional = true;   
    $.ajax({
        url: '/property/deleteimages',
        type: 'POST',
        data:  imgList ,
        success: function(result){
            alert("ok");
        }
    });
...


public ActionResult DeleteImages(int[] data)
        {
            return PartialView(data);            
        }

Upvotes: 0

Views: 95

Answers (1)

AliRıza Adıyahşi
AliRıza Adıyahşi

Reputation: 15866

try

$.ajax({
    url: '/Property/DeleteImages',
    type: 'POST',
    data:  { data : imgList },
    traditional : true,
    success: function(result){
        alert("ok");
    }
});

Upvotes: 1

Related Questions