.net mvc ajax 传递多个对象的方法
参考资料 http://www.cnblogs.com/wubh/p/6253358.html
http://blog.csdn.net/zengweiqiang/article/details/7354006
$.ajax({
type: "post",url: "/Test/testST",
data: JSON.stringify({
model: {
user: "sfds",
password:"66655tttt"
},
testobj: {
name1: "111111",
name2: "2222222"
}
}
),
contentType: 'application/json',
async: true,
success: function (result) {
alert(result);
}
});
.net后台获取 json数据
public static string getRequestPayload(HttpRequestBase Request)
{
Stream stream = Request.GetBufferedInputStream();
StreamReader sr = new StreamReader(stream);
return sr.ReadToEnd();
}
调用该方法前不能使用request对象读取数据,否则会报错
var obj1 = {};
obj1["model.user"] = "66666666";
obj1["model.password"] = "123456";
obj1["testobj.name1"] = "name1";
obj1["testobj.name2"] = "name2";
$.ajax({
type: "post",
url: "/Test/testST",
data: obj1
,
async: true,
success: function (result) {
alert(result);
}
});