I read about the binding of models in asp.net and came across this obzats:

Only one parameter in the action method can add [FromBody]. ASP.NET Core MVC passes responsibility for reading the request stream to the formatter. After reading the stream, it cannot read the stream again to bind other [FromBody] parameters.

Link to article

Why is that? And suppose I send the following line to the server: {"value":"1"} - should I create a separate class for it to accept it? Because public void Post([FromBody]int value) does not work

  • Yes, create a separate class. Or write your complete binder, which will parse the request using its own attributes. - Pavel Mayorov

2 answers 2

The reason is that the request body can be saved to an unbuffered stream that can only be read once.

Here everything is described in detail .

    If it suddenly happens (it is not clear how and why) the need to accept 2 parameters in a POST request, then it’s easier on the client’s side to push their objects into a single object, then create a received parameter of type dynamic on the controller and split it into 2 or more object ... Well, or create a model =)

    • "If it suddenly happens (it is not clear how and why) the need to accept 2 parameters in a POST request" - in the sense of how and why? It's kind of common practice, isn't it? - Qutrix pm
    • No, there is always one model (one object) - gromanev