Asp.net Core 2 API POST Objects are NULL?

You need to include the [FromBody] attribute on the model:

[FromBody] MyTestModel model

See Andrew Lock’s post for more information:

In order to bind the JSON correctly in ASP.NET Core, you must modify your action to include the attribute [FromBody] on the parameter. This tells the framework to use the content-type header of the request to decide which of the configured IInputFormatters to use for model binding.

As noted by @anserk in the comments, this also requires the Content-Type header to be set to application/json.

Leave a Comment