0

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.

alanextar
  • 1,094
  • 13
  • 16
  • To rephrase the question *and* the title, you want to use a single action with multiple content types. That's completely different from what you asked. It's far more likely to get good answers if you ask about the actual problem, not what you think the solution is. – Panagiotis Kanavos Jul 02 '21 at 15:04
  • Asking about the assumed solution instead of the actual problem is called [The XY Problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) and can be very frustrating and wasteful – Panagiotis Kanavos Jul 02 '21 at 15:06
  • I think you rephrase question wrong cause by default net core bind from different sources using different content type (see the top of question description). I'm interested specifically in json and form binding. I wanted to show what I've already found and it doesn't fit me – alanextar Jul 02 '21 at 16:43
  • Deleted the part about value provider but I think using something similar to FormValueProvider would solve a problem – alanextar Jul 02 '21 at 16:45

0 Answers0