As it is given in the tutorial, the HttpPost "Create" function will not allow you to enter new data.
Given the JSON{
"name":"walk dog",
"isComplete":true
}
, the object that is read in by the controller is
Updating the function signature to public IActionResult Create([FromBody]TodoItem item)
allows the request data to be read properly.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@pobartlett I can't reproduce this problem. The sample download works fine.
@pobarlett I think the issue is because you may have forgot to anótate the controller class with the [ApiController]
attribute.
@pobartlett I suspect the suggestion from @Dc9894 will fix the problem. The [FromBody]
attribute is only inferred for complex types when the controller is annotated with [ApiController]
. [ApiController]
, of course, requires ASP.NET Core 2.1 or later. For ASP.NET Core 2.0 and below, the [FromBody]
attribute is required.
Most helpful comment
@pobarlett I think the issue is because you may have forgot to anótate the controller class with the
[ApiController]
attribute.