FromForm is an ASP.NET Core parameter-binding attribute that tells model binding to read a parameter or property from form data posted in the request body. section 16.2.3
Use FromForm when you need to override the default binding source:
- Apply it to handler parameters or properties in Razor Pages and MVC controllers. section 16.2.3
- Do not combine it with FromBody for the same value; both consume the request body and are effectively mutually exclusive. section 16.2.3
- Note that FromForm is unavailable in minimal APIs. section 16.2.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 */
}
}
Compare FromForm with FromHeader and FromBody while reviewing binding-source annotations on an OnPost handler. section 16.2.3
