javascript - sending array of ints from js to the controller -


inside view have list of images corresponding checkboxes. want check image or images , store image id's int array. int array should sent controller further process.

i'm spend time on , i'm getting int[] data null @ controller

question is: why i'm getting null @ controller?

solved! in _layout jquery scripts bundle call @ end of document, when move top works.

view

<div id="newsimages">     <img width="50" height="50" alt="" src="/imageone.jpg">             <input type="checkbox" class="imgcheckbox" id="4">        <img width="50" height="50" alt="" src="/imagetwo.jpg">             <input type="checkbox" class="imgcheckbox" id="5">        <input type="button" value="delete" name="deleteimgbtn" id="deleteimgbtn" class="deleteimagesbtn">     </div> 

js

var imglist = []; $(document).on("click", "#deleteimgbtn", function (e) {     e.preventdefault();     $('.imgcheckbox:checked').each(function () {                 var id = $(this).attr('id');         //add image id array of ints         imglist.push(id);     });     jquery.ajaxsettings.traditional = true;         var options = {         url: '/news/deleteimages',         type: 'post',                 data: { data: imglist },         traditional: true     };     $.ajax(options).done(function (data) {         var $target = $('#newsimages');         $target.html(data);     });     //reset array of int prevent browser send duplicated      //img id controller on second attempt after ajax request completed     imglist.length = 0;     //prevent browser default actions     return false; }); 

controller

public actionresult deleteimages(int[] data) {   ... } 

you can seralize array , send via ajax.

serializing json in jquery

and read seriazlized array, parse it..check every thing , go


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -