Hi @Ronald Rex ,
If you want to get the ID to be sent to IHttpActionResult Put Verb Action Method,
You can get the id directly after the url:
url: '/api/product?id=' + id,
I make a simple example:
$(function () {
//for testing purpose
var id = 5;
var product = { "pname": "p001" };
productUpdate(id, product);
})
function productUpdate(id, product) {
$.ajax({
url: '/api/product?id=' + id,
type: 'PUT',
contentType:
"application/json;charset=utf-8",
data: JSON.stringify(product),
success: function (product) {
/* productUpdateSuccess(product);*/
},
error: function (request, message, error) {
handleException(request, message, error);
}
});
}
public IHttpActionResult Put(int id, Product product)
{
IHttpActionResult ret = null;
if (Update(product))
{
ret = Ok(product);
}
else
{
ret = NotFound();
}
return ret;
}
public class Product
{
public string pname { get; set; }
}
If the answer is helpful, please click "Accept Answer" and upvote it.
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,
Lan Huang