To send an array of objects to a controller in ASP.NET 6 (Core), you can use the [FromBody]
attribute in the controller method signature. Here is an example:
public class Item
{
public int Id { get; set; }
public string Name { get; set; }
}
Item
objects:[HttpPost]
public IActionResult MyControllerMethod([FromBody] Item[] items)
{
// Do something with the items array
return Ok();
}
[
{ "id": 1, "name": "Item 1" },
{ "id": 2, "name": "Item 2" },
{ "id": 3, "name": "Item 3" }
]
Note that the Content-Type
header of the request must be set to application/json
to indicate that the data in the body is in JSON format.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-07-01 11:00:00 +0000
Seen: 12 times
Last updated: Feb 18 '22
Is it possible to utilize EF Core migrations if the EF code is distributed among various solutions?
How can Gitlab CI be utilized for ASP.NET Core 7 by utilizing Docker Images on an on-premise server?
Are there any available clients for ASP.NET Core websockets in Unity?
What is the process to turn off the event logging feature in ASP.NET core microservices?
How can I view the Resources window in Microsoft Blend 2019 for a .Net Core WPF project?