Reputation: 2503
GET works fine. In the Controller I have this method:
[HttpPost]
public IHttpActionResult Post(Product product)
{
var isSaved = productService.SaveProduct(product);
if (isSaved == true) return Ok();
else return BadRequest();
}
The problem is, product is null. I get to this method (via a breakpoint) but am not sure why the product is null. Here's what's in Fiddlers Composer:
User-Agent: Fiddler
host: localhost:53882
Content-Type: application/json; charset=utf-8
Content-Length: 54
And this is the Fiddler request body:
{
id:5,
name: Dress,
price: 39.90,
quantity:71
}
There's no model. It's all in the db (edmx). It works for getting a list of products, or a product by product id.
Upvotes: 1
Views: 181
Reputation: 1331
I think the issue could be with contentType, you should include in the header Content-Type: application/json
and yes also the json you are posting is not valid : Name: "Dress",
Upvotes: 0
Reputation: 14889
The name
in your request body is missing the double quotes. Make sure the cases matches as your model because it is case-sensitive.
{
id:5,
Name: "Dress",
Price: 39.90,
Quantity:71
}
Upvotes: 3