liveBook · Manning

Form data

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

A form value is a named field value submitted in the body of an HTTP request by an HTML form.

Form data is a named field value submitted in the body of an HTTP request when an HTML form uses POST. In Razor Pages, model binding turns matching form values into PageModel properties or handler parameters. section 16.2

Razor Pages processes form data as part of model binding:

  • The model binder checks form values, route values, and query string values in that order, using the first matching value. section 16.2
  • Bound values are validated and assigned to PageModel properties or passed to page-handler parameters. section 16.2
  • Razor Pages binds form bodies by default, unlike minimal APIs, which do not support the same default form-body binding behavior. section 16.2
Listing 16.1 Model binding requests to properties in a Razor Page
public class IndexModel: PageModel
{
    [BindProperty]                            #1
    public string Category { get; set; }      #1
 
    [BindProperty(SupportsGet = true)]        #2
    public string Username { get; set; }      #2
 
    public void OnGet()
    {
    }
 
    public void OnPost(ProductModel model)    #3
    {
    }
}

The example shows form-bound properties alongside a page-handler parameter, illustrating two ways submitted values can reach Razor Page code. section 16.2

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

How deep it goes
Defines request-body form values and traces their binding, validation, and delivery, but defers generating forms with Razor syntax and Tag Helpers.
Examples
Demonstrates Category and Username properties plus a ProductModel handler parameter receiving bound values.
What you can do after
Apply it via Razor Pages to receive submitted fields in properties or page-handler parameters.
How it connects
Connects form data with model binding, validation, HTTP requests, route values, query strings, Razor Pages, and minimal APIs.

Also explained in

Compare how 3 books explain form data →

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.