passing array from javascript to controller MVC 4

前端 未结 4 1363
抹茶落季
抹茶落季 2021-01-22 23:19

I am using razor and I\'m having a hard time passing an array to a controller. the array contains objects that I made and I am trying to do this:

$.ajax({
     t         


        
4条回答
  •  佛祖请我去吃肉
    2021-01-22 23:26

    Add "traditional:true" parameter in your ajax.

    Example:

    var parentValueToPush=new Array();
    $('[name=SelectedUsers]:checked').each(function () {
                parentValueToPush.push($(this).val());
                temp.push($(this).val());
            });
            $.ajax({
                url: //URL,
                type: 'get',
                traditional: true,
                dataType: 'html',
                cache: false,
                data: { SelectedUsers: parentValueToPush},
                success: function (data) {
                       //Result
                }
            });
    

提交回复
热议问题