小编Ron*_*mos的帖子

如何在 .NET Core 3.0 Preview 9 中正确实现 JsonPatch?

我正在尝试在 .NET Core 3.0 Preview 9 web api 上实现 JsonPatch。

该模型:

public class TestPatch
{
    public string TestPath { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

Web API 端点:

[HttpPatch()]
public async Task<IActionResult> Update([FromBody] JsonPatchDocument<TestPatch> patch)
{
   ...........
   return Ok();
}
Run Code Online (Sandbox Code Playgroud)

JSON 有效负载:

[
    {
        "op" : "replace",
        "path" : "/testPath",
        "value" : "new value"
    }
]
Run Code Online (Sandbox Code Playgroud)

通过 Postman 使用 PATCH,我收到此错误:

{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "|492c592-4f7de4d16a32b942.",
"errors": {
    "$": [
        "The JSON value could …
Run Code Online (Sandbox Code Playgroud)

asp.net .net-core asp.net-core-3.0 .net-core-3.0

7
推荐指数
2
解决办法
3969
查看次数