From javascript I sent to a webmethod the following :
var firstname = $("#txtfirstname").val();
var lastname = $("#txtlastname").val();
var dataFilter = { "filterType": "fn_ln", "data": { "firstName": firstname, "lastName": lastname } }
var data = JSON.stringify(dataFilter)
data = data.replace(/\"/g, '\'');
datatoSend = '{ filters:"' + data + '" }';
I use data.replace(/\"/g, '\''); so the webmethod can accepts the data(without that I get an error 500 from webmethod)
Once in the web method I receive
"{'filterType':'fn_ln','data':{'firstName':' aa','lastName':' bb'}}"
as the parameter. Then with c#, when I try.
JavaScriptSerializer sr = new JavaScriptSerializer();
srFilterData filterin = sr.Deserialize<srFilterData>(filters);
I get an error saying that No parameterless constructor defined for type of 'System.String[]
This is my class:
[Serializable]
public class srFilterData
{
public String filterType { get; set; }
public String data { get; set; }
}
Whats the problem?