Confused with FromBody in ASP.NET Core

前端 未结 3 619
礼貌的吻别
礼貌的吻别 2020-12-18 18:23

I have the following WEB API method, and have a SPA template with Angular:

[HttpPost]
public IActionResult Post([FromBody]MyViewModel model)
<
3条回答
  •  Happy的楠姐
    2020-12-18 19:04

    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.

    Microsoft documentation for the ApiController attribute

提交回复
热议问题