//类定义
public class Users
{public int UserID;
public string UserName;
public string UserEmail;
}
//webapi post 写法
[HttpPost]
public Users Post([FromBody] Users value)
{
_userList.Add(value);
return value;
}
//ajax post
function post() {
$.ajax({
url: "http://localhost:5000/api/Users",
type: "POST",
contentType: "application/json; charset=utf-8",
data: '{ "UserID": 1,"UserName": "test","UserEmail": "test@cnblogs.com" }',
dataType: 'json',
success: function (data) {
alert(JSON.stringify(data));
}
});
}
//json对象 序列化 推荐使用 JSON.stringify(obj);