反序列化列表对象,返回为null

时间:2017-07-29 23:54:34

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

我尝试将数据发布到应接受List<UpdatePointHistory>的API。列表的大小是正确的,但对象的属性是空白的。

public class UpdatePointHistory
{
    string Tree { get; set; }
    string FruitCount { get; set; }
    string Observations { get; set; }
    int PrivateId { get; set; }
}

public void Post([FromBody]List<UpdatePointHistory> updates)
{
    //Do some sort of auth for god sake
    Console.WriteLine("test");
}

我发布的数据:

enter image description here

从API返回的对象:

enter image description here

1 个答案:

答案 0 :(得分:5)

您的所有媒体资源均为private。它们需要为public,因此模型绑定器知道要填充的内容并可以访问它们。

public class UpdatePointHistory
{
    public string Tree { get; set; }
    public string FruitCount { get; set; }
    public string Observations { get; set; }
    public int PrivateId { get; set; }
}
相关问题