liveBook · Manning

BindProperties

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

BindProperties is an ASP.NET Core Razor Pages attribute that enables model binding for every property on a PageModel.

BindProperties is an ASP.NET Core Razor Pages attribute applied to a PageModel. It makes every property on that PageModel participate in model binding, so request values can populate the model automatically. section 16.4 section 16.2

Use it cautiously: broad binding can accidentally include properties you did not intend to accept, increasing the risk of overposting and making the binding behavior less explicit. section 16.4 section 16.2

Prefer narrower alternatives when they fit the page:

  • Apply BindProperty to one property, commonly an InputModel, when a form needs request values available to the Razor view. section 16.4 section 16.2
  • Add simple values such as product IDs directly to page-handler parameters when the view does not need them afterward. section 16.4 section 16.2
  • Validate bound user input before using it, regardless of which binding approach you choose. section 16.4

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

How deep it goes
Defines PageModel-wide binding and compares alternatives, but stops short of detailed attribute mechanics or implementation internals.
Examples
Contrasts PageModel-wide binding with BindProperty on an InputModel and handler parameters for product IDs.
What it assumes
Assumes familiarity with Razor Pages PageModels and handlers while emphasizing validation of user input.
What you can do after
Evaluate binding choices and select explicit property or handler-parameter binding to reduce accidental data binding.
How it connects
Connects model binding with PageModel properties, page-handler parameters, InputModel, Razor views, and overposting attacks.

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.