Add note about multiple [FromBody] parameters in ModelBinding (#1662)
* Add note about multiple [FromBody] parameters in ModelBinding * word smith * word smithpull/1669/head
parent
169da99c89
commit
c398c53ac9
|
@ -74,6 +74,8 @@ Binding formatted data from the request body
|
|||
|
||||
Request data can come in a variety of formats including JSON, XML and many others. When you use the [FromBody] attribute to indicate that you want to bind a parameter to data in the request body, MVC uses a configured set of formatters to handle the request data based on its content type. By default MVC includes a ``JsonInputFormatter`` class for handling JSON data, but you can add additional formatters for handling XML and other custom formats.
|
||||
|
||||
.. Note:: There can be at most one parameter decorated with ``[FromBody]``. The ASP.NET Core MVC run-time delegates the responsibility of reading the request stream to the formatter. Once the request stream is read for a parameter, it's generally not possible to read the request stream again for binding other ``[FromBody]`` parameters.
|
||||
|
||||
.. Note:: The ``JsonInputFormatter`` is the default formatter and it is based off of `Json.NET <http://www.newtonsoft.com/json>`_.
|
||||
|
||||
ASP.NET selects input formatters based on the `Content-Type <https://www.w3.org/Protocols/rfc1341/4_Content-Type.html>`_ header and the type of the parameter, unless there is an attribute applied to it specifying otherwise. If you'd like to use XML or another format you must configure it in the `Startup.cs` file, but you may first have to obtain a reference to ``Microsoft.AspNetCore.Mvc.Formatters.Xml`` using NuGet. Your startup code should look something like this:
|
||||
|
|
Loading…
Reference in New Issue