I've encountered various errors while passing parameters to my WebMethod
. Below are my attempts and the corresponding errors:
globalData
is an array, mapping
is an array that can be deserialized to List<Mapping>
, selectedFund
is an integer.
C# WebMethod
[WebMethod]
public static void ProcessData(string data, List<Mapping> mapping, int selectedFund)
{
//blah blah
}
Attempt 1
var payload = new Object();
payload.data = globalData;
payload.mapping = chosenMappings;
payload.selectedFund = $selectedFund.val();
$.ajax({
//...etc
data: JSON.stringify(payload),
contentType: "application/json; charset=utf-8",
}
Error: System.String
is not supported for serialization of an array.
Attempt 2
$.ajax({
//... etc...
data: {
data: JSON.stringify(globalData),
mapping: JSON.stringify(chosenMappings),
selectedFund: $selectedFund.val()
},
contentType: "application/json; charset=utf-8",
Error: Invalid Json primitive