I have the following WEB API method, and have a SPA template with Angular:
[HttpPost]
public IActionResult Post([FromBody]MyViewModel model)
I thought, based on this topic, there is no need to use [FromBody]
here, since I want to read the value from the message body, so there is no need to override the default behavior, but, if I don't use [FromBody]
, the model that is coming from Angular is null. I'm really confused, why should I use [FromBody]
, since I have used the default behavior?
For anyone seeing this issue .net core 3 - you need to add the [ApiController] to the controller where you extend ControllerBase. The [FromBody] is only needed if you're doing an MVC controller.
This causes the body to get automatically processed in the way you're expecting.