The [FromBody] attribute tells ASP.NET Core to read a parameter from the HTTP request body and deserialize JSON into its type. It overrides the framework’s usual binding conventions. section 7.3 section 7.2
Bind a list of photos
public void OnPost([FromHeader] string userId, [FromBody] List<Photo> photos) { /* use photos */ }\n\nA JSON request body is deserialized into the photos parameter, while userId comes from the request header. section 16.2.3
Use [FromBody] with these behaviors in mind:
- Razor Pages requires [FromBody] for JSON body binding; minimal APIs commonly infer the body source for complex parameters. section 16.2.3 section 7.3
- Apply it to simple types when you deliberately want body binding instead of route or query-string binding. section 7.3
- Avoid body binding on GET and similar verbs; unusual requests can fail at runtime and may confuse API consumers. section 7.3
- Allow only one eligible complex body parameter, or the application can throw when it receives a request. section 7.3
- Expect a 415 Unsupported Media Type response when the request body is not accepted JSON in the described configuration. section 7.3
Listing 16.5 Choosing a binding source for model binding
public class PhotosModel: PageModel
{
public void OnPost(
[FromHeader] string userId, #1
[FromBody] List<Photo> photos) #2
{
/* method implementation */
}
}
Inspect the complete handler signature to see body binding used alongside an explicitly selected header source. section 16.2.3

