liveBook · Manning

PageModel property

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

A PageModel property is a property on a Razor Page's PageModel that holds data available to the associated Razor view.

A PageModel property stores data that a Razor Page displays. Expose view-specific data as public properties on the PageModel, then assign values in the page handler. section 17.2.3

A task list PageModel

A PageModel can expose different kinds of data: a string for the title and a list for tasks. The OnGet handler assigns both before the view renders.

Choose other mechanisms when their specific purpose fits better:

  • Use ViewData for arbitrary keyed data or values needed by layout files. section 17.2.3
  • Use TempData for data that must survive until it is read during another request, commonly with POST-Redirect-GET. section 17.2.3

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

How deep it goes
Defines public properties and demonstrates assignments, but does not explain rendering internals or property binding.
Examples
Demonstrates a ToDoItemModel with Title and Tasks properties populated by OnGet.
What you can do after
Build view data into public PageModel properties and populate it in a page handler.
How it connects
Connects PageModel properties with Razor views, page handlers, ViewData, TempData, and dependency injection.

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.