aspnet / JsonPatch

[Archived] JSON PATCH library. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
103 stars 48 forks source link

Cannot get this to work in ASP.NET Core MVC #16

Closed benfoster closed 8 years ago

benfoster commented 8 years ago

Controller:

        [HttpPatch]
        public IActionResult Patch(JsonPatchDocument<Contact> patch)
        {
            patch.ApplyTo(contact, ModelState);

            if (!ModelState.IsValid)
            {
                return new BadRequestObjectResult(ModelState);
            }

            return Ok(contact);
        }

When I make the following request:

PATCH /api/contacts HTTP/1.1
Host: localhost:51834
Content-Type: application/json-patch+json
Cache-Control: no-cache

[{ "op": "add", "path": "/firstname", "value": "John" }] 

No operations are bound to the patch parameter and therefore no changes are made.

benfoster commented 8 years ago

Missing [FromBody]

doh!