Confused with FromBody in ASP.NET Core

前端 未结 3 625
礼貌的吻别
礼貌的吻别 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条回答
  •  太阳男子
    2020-12-18 19:14

    The question you linked to is referring to web-api. You are using core-mvc which has been re-written to merge the pipelines for the previous mvc and web-api versions into one Controller class.

    When posting json (as apposed to x-www-form-urlencoded), the [FromBody] attribute is required to instruct the ModelBinder to use the content-type header to determine the IInputFormatter to use for reading the request.

    For a detailed explanation of model binding to json in core-mvc, refer Model binding JSON POSTs in ASP.NET Core.

提交回复
热议问题