Can I have both FromForm and FromBody attributes to action ?
public IActionResult Index([FromBody][FromForm] Person model){ ..... }
[FromForm] - Gets values from posted form fields. [FromBody] - Gets values from the request body.
Please note that we are able to send [FromBody] parameter in HTTP GET Request input.
Using [FromBody] When a parameter has [FromBody], Web API uses the Content-Type header to select a formatter. In this example, the content type is "application/json" and the request body is a raw JSON string (not a JSON object).
Model binding allows controller actions to work directly with model types (passed in as method arguments), rather than HTTP requests. Mapping between incoming request data and application models is handled by model binders.
No, it's not possible.
The FromForm
attribute is for incoming data from a submitted form sent by the content type application/x-www-form-urlencoded
while the FromBody
will parse the model the default way, which in most cases are sent by the content type application/json
, from the request body.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With