我将 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 时我需要做其他事情吗?