1 | initial version |
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.