I'm trying to send this json to my controller
{
"Name":"Ford Focus",
"CarProperties":[
{
"Name":"Airbag"
}
]
}
As you see there is a Collection named as CarProperties. I want to handle this collection in my Controller function. But getting null.
Controller
public class TestController : ApiController
{
public CarViewModel PostCar(CarViewModel car)
{
//Here is the error
// Output is : {"Name":"Ford Focus"} so, car.CarProperties has come as null
return car;
}
}
View Models
public class CarPropertyViewModel {
public string Name;
}
public class CarViewModel
{
public string Name;
public List<CarPropertyViewModel> CarProperties { get; set; }
}
What I am doing wrong?
CarProperties: [{ "CarPropertyID":1, "Name":"Airbag" }]
in order to bind to a collection. Alternatively, change the model to ` public CarPropertyViewModel CarProperties { get; set; }` and makeName
a property as well (fields are not bound) – Hyonhyoscine