Attribute - AspNetCore.Mvc

Namespace Microsoft.AspNetCore.Mvc

FromBody

Controller

1
2
3
4
5
[HttpPost]
public async Task<ActionResult<Artist>> AddArtist([FromBody] Artist artist)
{
...
}

Postman collection -> Body, Raw, Json

1
2
3
4
{
"Id": "f22e850e-4b31-417d-bc4b-4813ba98a50c",
"Name": "Carl Paton"
}

FromForm

Controller

1
2
3
4
5
[HttpPut]
public async Task<ActionResult<Artist>> UpdateArtist([FromForm] Guid id, [FromForm] string name)
{
...
}

Postman collection -> Body, form-data

1
2
3
4
KEY             VALUE
-------------------------------------------------------
Id f22e850e-4b31-417d-bc4b-4813ba98a50c
Name Carlos Poephole

FromRoute

Controller

1
2
3
4
5
[HttpPut]
public async Task<ActionResult<Artist>> UpdateArtist([FromRoute] Guid sweetId)
{
...
}

Postman collection -> PUT

1
http://localhost:5000/foo/{{sweetId}}/bar/{{id}}

FromQuery

1
2
3
4
public async Task<ActionResult<List<Artist>>> SearchArtist([FromQuery(Name = "q")] string searchOn)
{
...
}

Postman collection -> GET

1
2
3
KEY             VALUE
-------------------------------------------------------
q bob marley