【问题标题】:Update nested elements using ASP.NET core with json patch使用带有 json 补丁的 ASP.NET 核心更新嵌套元素
【发布时间】:2017-03-27 20:17:04
【问题描述】:

有人知道如何使用 asp.net core json 补丁更新项目的嵌套元素吗?

我尝试使用 xx.Operations.Add(new Operation<DataRequestModel>("Replace", $"schedules/{scheduleId}/status", null, DataRequestStatusEnum.ExtractionFailed));

但是当我在补丁操作中使用model.ApplyTo(dataRequest); 时,它会引发异常The path segment '43688769-f45e-4e84-a8d6-f071c077b9ad' is invalid for an array index.

感谢您的帮助。

【问题讨论】:

    标签: c# asp.net json asp.net-core json-patch


    【解决方案1】:

    我通过使用

    做到了这一点

    控制器

        [Route("{some}/adress")]
        [HttpPatch]
        public bool YourDtoUpdate(long some, [FromBody]JsonPatchDocument<TestpDTO> testChanges)
        {
            var tsd = new TestDTO(){Nested = new NestedClass()};
            testChanges.ApplyTo(tsd);
        }
    

    服务

        var model = new TestDTO() { Foo = "abc", Nested = new NestedClass()};
        JsonPatchDocument<TesDTO> patchDoc = new JsonPatchDocument<TestDTO>();
        patchDoc.Replace(e => e.Foo , model.Foo );
        patchDoc.Replace(e => e.Nested.Bar, model.Nested.Bar);
    

    【讨论】:

      猜你喜欢
      • 2021-03-13
      • 2021-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-08
      • 1970-01-01
      • 2021-04-17
      相关资源
      最近更新 更多