Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I have data similar to this:

var data = {
        email: $("#txtEmail").val(),
        password: $("#txtPassword").val()
    }
    data = JSON.stringify(data);

I use jquery ajax and pass this data to my web method. This all works if my webmethod is like this:

[WebMethod]
    public static Response TryLogin(string email, string password) {..}

But I am trying pass the data to a web method that looks like this:

[WebMethod]
    public static Response TryLogin(LoginData data) {..}

My LoginData class looks similar to this:

public class LoginData
        {
            public string email { get; set; }
            public string password { get; set; }
        }

When I try to do it this way I receive the following error:

error: 500: {"Message":"Invalid web service call, missing value for parameter: \u0027data\u0027.

How do I do this properly?

share|improve this question
    
Your question help me to solve my three days problem Thanks! – Vijay Kumbhoje Nov 4 '15 at 9:52
up vote 3 down vote accepted
data = JSON.stringify({data: data});

To elaborate, you are currently sending 2 parameters, whereas your web method expects just one (named data).

share|improve this answer
    
Yup. That's working perfect! – e-zero Mar 8 '13 at 15:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.