Deserializing list objects, properties returning as null

139 Views Asked by At

I'm trying to POST data to an API which should accept a List<UpdatePointHistory>. The size of the list is correct but the properties of the objects are blank.

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");
}

The data I'm posting:

enter image description here

And the object returning from the API:

enter image description here

1

There are 1 best solutions below

0
On

All your properties are private. They need to be public so the model binder knows what to populate and has access to them.

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