2017-07-29 110 views
0

我试图将数据发布到应该接受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

+2

您的所有属性都是“private”。它们需要是“公共”的,所以模型绑定器知道要填充什么 – Nkosi

回答

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; } 
} 
相关问题