参考:
ajax调用实例
<script>
var user = { name_CN: "haha", pwd: "123"};
var userToken = "gado23asdf23";
var data = JSON.stringify({ User: user, UserToken: userToken });
alert(data.toString());
$.ajax({
type: "post",
url: "../api/Login/Test",
dataType: "json",
data: data,
contentType: "application/json",
cache: false,
error: function (x, c, e) {
if (c == "error") {
$(this).val(c);
}
},
success: function (r) {
alert(r);
}
});
</script>
后台action接受
[HttpPost]
public string Test(dynamic User)
{
JObject userJson = User.User; //获取动态对象中子对象
string userToken = User.UserToken;
var user = userJson.ToObject<WD_Employee>(); //将其转换为强类型对象
return "1";
}