POST http://localhost:55924/api/Product HTTP/1.1
User-Agent: Fiddler
Host: localhost:55924
Content-Type: application/json; charset=utf-8
Content-Length: 84
{"Ean″:”1122u88991″,”Name″:”Post test″,"Description":"Post test desc"}
但是Post方法总是返回null。
// POST api/Product
[HttpPost]
public IActionResult PostProduct([FromBody]Product product)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
_repo.Add(product);
return CreatedAtRoute("GetToode",product);
}
当我使用 [FormBody] 产品时始终为空,不使用时产品被评估但所有字段均为空。产品类别简单。
public class Product
{
public int ProductID { get; set; }
public string EAN { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int? CategoryID { get; set; }
}