reactjs - 在反应和 Web-API 项目之间连接 - 对象以 null 和 0 到达服务器
问题描述
我有一个用 React 和 web API-C# 编写的项目,
当我发送一个带有数据的发布请求时,它涉及用 null 和 0 初始化的控制器
在反应中设置对象:
class user {
UserID
FirstName
LastName
SMS
Email
Phone
RoleID
UserName
Password
Dock
DocName
status
constructor(userID = null, FirstName = null, LastName = null, SMS = null, Email = null, Phone = null, RoleID = null, userName = null, Password = null, document = null, docName = null, status = true) {
this.UserID = userID
this.FirstName = FirstName
this.LastName = LastName
this.SMS = SMS
this.Email = Email
this.Phone = Phone
this.RoleID = RoleID
this.UserName = userName
this.Password = Password
this.Dock = document
this.DocName = docName
this.status = status
}
}
export default user
在 C# 中:
public class UserDTO
{
public int UserID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string SMS { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public int RoleID { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public string Dock { get; set; }
public string DocName { get; set; }
public string status { get; set; }
public UserDTO()
{
}
}
发送到服务器:
const use1 = new UserObject(1, 'aa', 'bb', null, null, null, 3);
return (
<div>
<button onClick={() => { Axios.post('https://localhost:44368/api/User/AddUser', JSON.stringify((use1)),).then(res => { console.log(res.data) }) }} >post with object</button>
</div>
)
在客户端它已满,
在服务器中,
解决方案
推荐阅读
- c# - 当我在 uwp 中使用 x:bind 时出错:无效的绑定路径错误
- opengl - 无法使用 freetype 将字形渲染到 OpenGL 纹理
- azure - Blob 存储数据集的 Azure 数据工厂通配符文件夹名称
- android - 在应用程序更新中不适用于应用程序包 apk
- kubernetes - Kubernetes 中的容器能否确定自己的资源利用率和限制?
- string - sed - 用特殊字符替换字符串
- laravel-5 - 通过 jwt / zizaco/entrust 使用角色
- javascript - Codecademy howOld 语法错误在 else if
- asp.net - 某些应用程序别名会导致 Error401.2:IIS 上出现未经授权的消息
- deep-learning - 用大量图像训练强化学习模型