问题
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?
来源:https://stackoverflow.com/questions/40545603/mvc-rest-api-unable-to-get-collection-in-json-parameter