Click here to Skip to main content
16,020,459 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to send the list or array of string to the controller. I am not able to get the value in the controller.

What I have tried:

 var selectedRowChartID = [];
$('.selectedrow').each(function () {
            selectedRowChartID.push($(this).find('td.hiddenField-chartID input[type=hidden]').val());
        });
$.ajax({
            type: 'post',
            url: '@Url.Action("SaveAuditTrail","DMS")',
            async: false,
            cache: false,
            data: { "chartIDList": selectedRowChartID },
            success: function (data) { },
            error: function () { alert(selectedRowChartID); }
            });
        });
Posted
Updated 1-Mar-17 0:01am
Comments
Karthik_Mahalingam 1-Mar-17 2:48am    
post the controller action.
what error you are getting?

try this

var selectedRowChartID = ['a', 'b'];
       var obj = JSON.stringify({ chartIDList: selectedRowChartID });
       $.ajax({
           type: 'post',
           url: '@Url.Action("SaveAuditTrail", "DMS")',
           contentType: 'application/json; charset=utf-8',
           async: false,
           cache: false,
            data: obj,
           success: function (data) { },
           error: function () { alert(selectedRowChartID); }
       });
 
Share this answer
 
C#
$.ajax({
            type: 'post',
            url: '@Url.Action("SaveAuditTrail","DMS")',
            async: false,
            cache: false,
            data: { "chartIDList": selectedRowChartID },
            traditional:true,
            success: function (data) { },
            error: function () { alert(selectedRowChartID); }
            });
        });


This works. Added
traditional:true,
in the ajax call.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900