簡體   English   中英

C# HttpPost-Postman Json 總是 null

[英]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 發送的

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM