1

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?

1 Answer 1

1

Use your C# class as follows:

[Serializable]
public class srFilterData
{
    public String filterType { get; set; }
    public UserData data { get; set; }
}


[Serializable]
public class UserData
{
    public String firstName { get; set; }
    public String lastName { get; set; }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.