Reputation: 6156
I want to send and work on multidimensional array in c# webmethod for that i have done some work.I dont want to run the ajax function in loop.
ASPX page code
var trip_id = $("#example1").val();
var user_id = $("#example2").val();
var facebookData = [];
facebookData[0] = trip_id;
facebookData[1] = user_id;
var fnds_list_array=[];
fnds_list_array=[["0678678678","XYZ","something.jpg"],["432524352","ABC","somethingABC.jpg"]]
var jsonData = JSON.stringify({ fb_Data: facebookData, fb_user_data: fnds_list_array });
$.ajax({
type: "POST",
url: "Ajax_function/myfunction.asmx/insert_custom",
data: jsonData,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess_insert_custom,
error: OnErrorCall
});
function OnErrorCall()
{ console.log("OHHH there is a mistake");}
function OnSuccess_insert_custom(response)
{ console.log("SUCESS");}
Webmethod Code
[WebMethod]
public string[] insert_custom(List<string> fb_Data,List<string> fb_user_data)
{
string temp = "";
string tripid = fb_Data[0];
string owner_id = fb_Data[1];
string fb_all_data;
string fb_id_user;
string fb_name;
string fb_img_src;
for (int i = 0; i < fb_user_data.Count; i++)
{
fb_all_data=fb_user_data[i];
string[] spltVal = fb_all_data.Split(',');
for (int j = 0; j < spltVal.Length; j++)
{
fb_id_user=spltVal[0];
fb_name = spltVal[1];
fb_img_src = spltVal[2];
temp = inFn.insert_custom(tripid, owner_id, fb_id_user, fb_name, fb_img_src);
}
}
// }
string[] arr1 = new string[] { temp };
return arr1;
}
But I am getting following error
"Type 'System.String' is not supported for deserialization of an array."
NOTE: fnds_list_array
is not static ..It can increase or decrease
Upvotes: 0
Views: 1525
Reputation: 761
See below example, I was not able to test it. but it can show you some way to your problem.
[WebMethod]
public static string[] insert_custom(List<MyTest> fnds_list_array)
{
}
public class MyTest
{
publc int Id
{ get; set;}
publc string Name
{ get; set;}
publc string ImageName
{ get; set;}
}
Upvotes: 0