FromBody is a strange attribute in that the input POST values need to be in a specific format for the parameter to be non-null, when it is not a primitive type. (student here)
- Try your request with
{"name":"John Doe", "age":18, "country":"United States of America"}
as the json. - Remove the
[FromBody]
attribute and try the solution. It should work for non-primitive types. (student) - With the
[FromBody]
attribute, the other option is to send the values in=Value
format, rather thankey=value
format. This would mean your key value ofstudent
should be an empty string…
There are also other options to write a custom model binder for the student class and attribute the parameter with your custom binder.