alanextar
alanextar

Reputation: 1314

Is it possible to route and bind multiple content types to the same action?

From microsoft docs:

By default, model binding gets data in the form of key-value pairs from the following sources in an HTTP request:

  1. Form fields
  2. The request body (For controllers that have the [ApiController] attribute.)
  3. Route data
  4. Query string parameters
  5. Uploaded files

I'm intrested to know is there a way to add model binding from body data not using ApiControllerAttribute.

The reason I ask this question is that we migrate from asp net 5 to net core 5 and we want to bind model parameters independet on with what content-type request comes: with content-type: x-www-form-urlencoded or with content-type application/json charset=utf-8

I've read a lot about this problem but only found a decision to separate method for each content-type using [FromBody] attribute as described in this article which doesn't fit me.

Upvotes: 0

Views: 327

Answers (0)

Related Questions