liveBook · Manning

FromForm

As explained in ASP.NET Core in Action, 3e

FromForm is an ASP.NET Core parameter-binding attribute that selects form fields in the request body as the source for a parameter or property.

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

How ASP.NET Core in Action, 3e covers it

How deep it goes
Defines explicit source selection and its body-binding conflict with FromBody, without detailing formatter or binder internals.
Examples
Shows binding-source annotations on an OnPost handler using FromHeader and FromBody as contrasting sources.
What you can do after
Apply it to a handler parameter or property to select posted form data for model binding.
How it connects
Connects model binding with FromHeader, FromQuery, FromRoute, FromBody, and minimal APIs.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.