【发布时间】:2019-10-24 13:11:48
【问题描述】:
我有一个带有多个补丁操作的 AspNetCore-WebApi-Project,它在 Core 2.2 上运行良好。迁移到 Core 3 后,[FromBody] JsonPatchDocument<T> 为空。我的 Get/Post-Methods 仍然按预期运行。
这是我创业的一部分:
services.AddDbContext<MyContext>(options => options
.UseLazyLoadingProxies()
.UseNpgsql(Configuration.GetConnectionString("MyConnectionString"),
opt => opt.UseNodaTime()));
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My-API", Version = "v1" });
});
services.AddControllers()
.AddNewtonsoftJson();
这是我的行动:
[HttpPatch("{id}")]
public async Task<IActionResult> Patch(Guid id,
[FromBody] JsonPatchDocument<MyViewModel> patchDocument)
{
await this.service.HandlePatchAsync(id, patchDocument);
return NoContent();
}
这是正文内容:
[
{
"op": "replace",
"path": "/name",
"value": "New Name"
},
{
"op": "replace",
"path": "/country",
"value": "Germany"
}
]
有人知道这里出了什么问题吗?
【问题讨论】:
-
您是否按照official documentation 将 2.2 迁移到 3.0?我对其进行了测试,效果很好。你能分享一个可以重现问题的演示吗?
-
我没有得到正确的包裹。我不清楚,除了调用 AddNewtonsoftJson() 之外,我已经安装了一个新包。在启动中。不过还是谢谢你看这个!
标签: asp.net-core .net-core json.net .net-core-3.0 json-patch