I want to post an object that has list of another object inside, MVC is receiving the object as null.
MVC Post
[HttpPost]
public ActionResult Create(ObjectWithList objectWithList) {
// While debugging objectWithList has its properties null
}
ObjectWithList
public class ObjectWithList
{
public List<Foo> Foo { get; set; }
public AnotherFoo AnotherFoo { get; set; }
}
Foo and AntoherFoo are classes with normal properties, like string, etc.
Using Postman I POST: Headers: Content-Type as application/json Body (raw):
{
"Foo": [
{
"Name": "test"
},
{
"Name": "test"
}
],
"AnotherFoo": {
"Name": "asd",
"Email": "[email protected]"
}
}
If I just pass "Foo" empty:
{
"Foo": [
{}
]
...
it works, (fills AnotherFoo). But as soon as i try to pass something inside Foo, MVC gets everything as null.
I'm correctly naming the properties of Foo and AnotherFoo on the JSON