Hi, I had a test in my side with your code snippet which worked well, I didn't reproduce your issue. I created a new .net 8 MVC application, and in the Index.cshtml, I have codes like below
<button onclick="saveOffer()">send request</button>
@section Scripts{
<script>
function saveOffer() {
alert(1);
var apiUrl = "https://localhost:7051/api/test?id=1";
var prodcutDoc = [
{ "op": "replace", "path": "/OfferDescription", "value": "changedDesc" },
{ "op": "replace", "path": "/OffferPercentage", "value": "changedPer" }
];
$.ajax({
url: apiUrl,
type: 'PATCH',
data: JSON.stringify(prodcutDoc),
contentType: 'application/json-patch+json',
accepts: 'application/json',
success: function (response) {
loadProductToUi(response);
},
error: function (error) {
console.log("Error in saveOffer:");
console.log(error);
alert("Error in saveOffer:" + error.responseText);
}
});
return true;
}
</script>
}
Then I followed this document to complete Patch request configuration, including adding .AddNewtonsoftJson(). Then please see my screenshot below, I create a simple ProductModel which worked well.
======================================
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Tiny