复杂的post参数始终为null

时间:2016-07-18 12:35:26

标签: c# asp.net-web-api

当我向后续行动提出要求时

[HttpPost]
public ResponseOutput Incremental(List<Product> inputList)
{
    return true;
}

参数inputList始终为null。我的目标:

public class Product
{
    public string ContractNo { get; set; }
    public string Sku { get; set; }
    public double Alis { get; set; }
    public string Kur { get; set; }
    public string SupplierNumber { get; set; }
    public ActionType Islem { get; set; }
}

ActionType是枚举。

我的请求机构:

POST /api/Konsinye/ConsigneeInsertIncremental HTTP/1.1
Host: localhost:38664
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 9e5f759c-552d-2e3e-f704-28ec91045e6c

{
 "inputList" : [
    {
      "ContractNo" : "123",
      "Sku" : "1234",
      "Alis" : "112",
      "Kur" : "TRY",
      "SupplierNumber" : "000",
      "Islem" : "1"
    }
  ]
}

问题是,参数始终为null。我尝试将[FromBody]添加到签名中,但它没有帮助。

1 个答案:

答案 0 :(得分:5)

尝试这种方法(将对象数组传输到服务器而不是具有数组属性的单个对象):

[HttpPost]
public IHttpActionResult Incremental(List<ConsigneeProductInput> data)
{
    return Ok();
}
来自邮递员的身体:

[
    {
      "ContractNo" : "123",
      "Sku" : "1234",
      "Alis" : "112",
      "Kur" : "TRY",
      "SupplierNumber" : "000",
      "Islem" : "1"
    }
]