我将一个ASP.NET Core 2.2 API更新到ASP.NET Core 3.0,并且我正在使用System.Json:
services
.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddJsonOptions(x => {})
我尝试使用之前可以正常工作的 Angular 8 发送 JSON 数据:
{
"name": "John"
"userId": "1"
}
ASP.NET Core 3.0 API中的模型是:
public class UserModel {
public String Name { get; set; }
public Int32? UserId { get; set; }
}
而 API 控制器操作如下:
[HttpPost("users")]
public async Task<IActionResult> Create([FromBody]PostModel) {
}
当我提交这个模型时,会出现以下错误:
The JSON value could not be converted to System.Nullable[System.Int32].
在使用System.Json而不是Newtonsoft时,我需要做其他事情吗?