I have an array filled like this:
updateLabels: function () { var diagrams = _stage.diagramLayer.getChildren(); var componentIDs = new Array(); for (var index = 0; index < diagrams.length; index++) { componentIDs.push(diagrams[index].componentID); } var self = this; $.ajax({ url: '../PlanView/UpdateDiagrams', type: 'POST', data: { ComponentIDs: JSON.stringify(componentIDs), RackInfo: $('#RackInfoSelect').val() }, success: function (data) { console.log('success'); }, error: function () { console.log("error"); } }); },
server side I have this method:
[CompressionFilterAttribute] public JsonResult UpdateDiagrams(List<int> componentIDs, string rackInfo) { List<object> diagramInformation = new List<object>(componentIDs.Count()); }
my data when it is transmitted over the network:
ComponentIDs:[74,445,732,351,348,347,1123,599,600,1053,350,601,602,603,332,99,877,919,349,348,347,347,349,348] RackInfo:Equipment Weight
I successfully get RackInfo, if I modify UpdateDiagrams to expect a List<string>
, then I get a list with one element in it, the entire string of ComponentIDs.
What am I doing wrong here?
EDIT: I work under MVC3. I should be able to use some automatic deserialization when moving to my controller, I'm just not sure how to do this.
SOLUTION: the solution was to wrap my data object in JSON.stringify, and not just the component identifiers. Although I can get the RackInfo variable on the server side without converting it to JSON.