I'm getting a 400 Bad Request when trying to calling a PATCH endpoint on my Web API (.Net Core 3.1) and I cannot figure out why. My action method looks like this:
using Microsoft.AspNetCore.JsonPatch;
namespace PropWorx.API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class OwnersController : ControllerBase
[HttpPatch("{id:int}")]
public async Task<ActionResult<Owner>> PatchOwner([FromRoute] int id, [FromBody] JsonPatchDocument<Owner> patchDoc)
{
if (patchDoc == null)
return BadRequest(ModelState);
var owner = await _context.Owners.FindAsync(id);
if (owner == null)
{
return NotFound();
}
patchDoc.ApplyTo(owner, ModelState);
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
await _context.SaveChangesAsync();
return new ObjectResult(owner);
}
}
}
And I am sending this to it in Postman:
{
"Op": "replace",
"Path": "/PropertyInspectId",
"Value": 10764
}
(I've also tried a string "10764" instead of an integer)
(Please see image below)
PropertyInspectId is a nullable integer and is definitely in the model and correctly spelt. I get the 400 error response immediately - before my API's action method even executes the first line of code.
Any ideas?