将JSON数据对象从jquery ajax传递到asp.net webmethod

将JSON数据对象从jquery ajax传递到asp.net webmethod,json,jquery,webmethod,Json,Jquery,Webmethod,我有类似的数据: var data = { email: $("#txtEmail").val(), password: $("#txtPassword").val() } data = JSON.stringify(data); public class LoginData { public string email { get; set; } public string pass

我有类似的数据:

var data = {
        email: $("#txtEmail").val(),
        password: $("#txtPassword").val()
    }
    data = JSON.stringify(data);
public class LoginData
        {
            public string email { get; set; }
            public string password { get; set; }
        }
我使用jQueryAjax并将这些数据传递给我的web方法。如果我的webmethod如下所示,则所有这些都可以工作:

[WebMethod]
    public static Response TryLogin(string email, string password) {..}
[WebMethod]
    public static Response TryLogin(LoginData data) {..}
但我正在尝试将数据传递给一个web方法,该方法如下所示:

[WebMethod]
    public static Response TryLogin(string email, string password) {..}
[WebMethod]
    public static Response TryLogin(LoginData data) {..}
我的LoginData类与此类似:

var data = {
        email: $("#txtEmail").val(),
        password: $("#txtPassword").val()
    }
    data = JSON.stringify(data);
public class LoginData
        {
            public string email { get; set; }
            public string password { get; set; }
        }
当我尝试这样做时,我收到以下错误:

错误:500:{“消息”:“无效的web服务调用,缺少参数值:\u0027data\u0027

我如何正确地做到这一点

data = JSON.stringify({data: data});

更详细地说,您当前发送了两个参数,而您的web方法只需要一个(命名数据)。

您的问题帮助我解决三天的问题,谢谢!