I am trying to post an array from jQuery on an .aspx page to a method in the codebehind using Telerik AjaxManager. The problem I am having is converting the string to a list or even an array using C#. The string (after using Json.stringify in jQuery) looks like this:
string zoneString = "[[1,[["Ticket Core.AFE"],["Ticket Core.CompanyName"]]],[2,[["Ticket Core.CompanyCity"],["Ticket Core.CompanyState"]]]]"
I tried to deserialize like this:
List<ZoneInfo> zones = JsonConvert.DeserializeObject<List<ZoneInfo>>(zonesString);
But that produced an error.
Here is my client-side code:
var zones = [];
for (var i = 1; i <= zoneCount; i++)
{
var o = $.data(listBox, i.toString());
if(o != undefined){var items = [];var a = o._array;
//pull the key/value
for (x = 0; x < a.length; x++)
{
var item = a[x];
var value = item.get_value();
value items.push([value]);
}
zones.push([i, items]);
}}
jsonZones = JSON.stringify(zones);
var ajaxManager = $find("<%= ((RadAjaxManager)this.Page.Master.FindControl("RadAjaxManager1")).ClientID %>"); ajaxManager.ajaxRequest('CREATEREPORT|' + jsonZones + '|' + tid);
Here is my server-side code:
protected void AjaxMgr_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
string[] args = e.Argument.Split('|');
string sCommand = args[0];
switch (sCommand.ToUpper())
{
case "CREATEREPORT":string zonesString = args[1];
List<ZoneInfo> zones = JsonConvert.DeserializeObject<List<ZoneInfo>>(zonesString);
var template = args[2];
string[] zone = new string[zones.Count];break;
}
InitializeWizard();}