![](/img/trans.png)
[英]C# web API POST JSON data using POSTMAN client results in always NULL in FromBody
[英]C# HttpPost-Postman Json always null
我正在嘗試將 Json 傳遞給 c# 中的 Web 服務。 但是當我通過 Json 時,我在 c# 中的 function 沒有保存它(返回 null)。 這是我的 c# 代碼。
[HttpPost]
public JsonResult test(Product producto)
{
var model = producto;
return Json(new { success = true, result = "My usuario es " + model.Name});
}
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public string Category { get; set; }
}
這就是我通過 postman 發送的
curl --location --request POST 'http://localhost/ws/test' \
--header 'Content-Type: application/json' \
--data-raw '{"Id":1,"Name":"abc","Category":"asd"}'
為什么當我嘗試獲取 producto.Name 時返回 null? 非常感謝你
更改您的操作 header:
public JsonResult test([FromBody]Product producto)
{
...your code
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.