- 实体类
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
2、webthod方法
[WebMethod]
public static User Insert(string q, User user)
{
return new User
{
Id = 111,
Name = "Mary",
Age = 18
};
}
3、ajax调用传参
function Test() {
var d = {
"q":"queryCondition",
"user":
{
"Id": 1,
"Name": '张三',
"Age": 18
}
};
$.ajax({
type: "POST",
contentType: "application/json",
url: "QueryExample.aspx/Insert",
dataType: "json",
data: JSON.stringify(d), //这里需将d转换为字符串
success: function (result) {
//var date = eval('new ' + eval(result.d.ProductDate).source) //从C#的DateTime类型转换为js的date类型
//获取返回实体类的值
var id = result.d.id;
var name = result.d.name;
var age = result.d.age;
},
error: function (error) {
alert(error.responseText);
}
});
}