我正在开发一个 ASP.Net Core 2 Web Api,但我不知道为什么我的 POST 方法的参数为 null。
我用 PostMan 测试过它:
然后我得到 proOrds
参数为空:
[HttpPost("[action]")]
public void Save([FromBody] List<Models.ProductionOrderPresentation> proOrds)
这是我发送的 JSON:
[{
"ProductionOrderId": 0,
"ProductId": 7,
"LawId": 0,
"Name": "rrrr",
"Created": null,
"Phase": 0,
"NumItems": 123,
"Reduction": 4444
}]
类是:
public class ProductionOrderPresentation
{
public int ProductionOrderId { get; set; }
public int ProductId { get; set; }
public byte LawId { get; set; }
public string Name { get; set; }
public string Created { get; set; }
public byte Phase { get; set; }
public int NumItems { get; set; }
public byte Reduction { get; set; }
}
这是怎么回事?
最佳答案
您的 Reduction
列的类型为 byte
,范围为 0-255,但您将 4444
作为该列的值传递。所以您发布的项目并没有真正映射到您的模型类,因此被 asp.net 忽略。
关于c# - POST 方法的参数始终为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47092248/