webapi ajax post .netcore 正确写法, 解决对象为空

前端之家收集整理的这篇文章主要介绍了webapi ajax post .netcore 正确写法, 解决对象为空前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

//类定义

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);

原文链接:https://www.f2er.com/ajax/161855.html

猜你在找的Ajax相关文章