PageModel
A PageModel is an ASP.NET Core Razor Pages class containing page state, data, and request-handling logic.
ASP.NET Core in Action, 3e
A PageModel code-behind file is the C# source file containing the handler methods and state for a Razor Page.
- How it is used
- Uses PageModel as the request-handling and view-data backing class for Razor Pages.
- How deep it goes
- Explains handlers, binding, service delegation, and view data through code examples, while deferring detailed binding and routing.
- Examples
- Uses a privacy page and a category-filtered to-do list to illustrate handlers, injected services, and view properties.
- What you can do after
- Apply PageModel in ASP.NET Core Razor Pages to handle requests, use services, and supply data to a view.
Pro ASP.NET Core 7, Tenth Edition
PageModel is the ASP.NET Core base class for classes that provide state and request handlers for Razor Pages.
- How it is used
- Handles Razor Page requests and supplies properties consumed by Razor markup.
- How deep it goes
- Explains creation, dependency injection, binding, handlers, redirects, validation, and filters; defers detailed model binding and CSRF mechanics.
- Examples
- Uses a product editor with GET and POST handlers and a session-backed shopping cart with handler tests.
- What you can do after
- Build it from scratch as a Razor Page model with request handlers, injected dependencies, and properties for rendering.
Read how Pro ASP.NET Core 7, Tenth Edition explains PageModel →
Also covered in
What to know first
- dependency injectionDependency injection is a software design technique in which a component receives its dependencies from outside rather than creating or locating them internally.
- loopA loop is a programming-language control-flow construct that repeatedly executes a block of instructions according to an iteration rule or continuation condition.
- HTTP GETHTTP GET is a safe, idempotent HTTP method that requests a representation of a resource without intending to change its state.
Related concepts
- handlerhas part · A handler is a software routine or component invoked to process an event, request, message, or other input.
- Razor Pagespart of · Razor Pages is an ASP.NET Core page-focused programming model in which independently addressable pages combine Razor markup with request-handling logic.
- model directiveconfigured by · The @model directive is a Razor directive that declares the model type associated with a page or view.
Questions about PageModel
What is PageModel?
A PageModel is an ASP.NET Core Razor Pages class containing page state, data, and request-handling logic.
Which Manning books explain PageModel?
ASP.NET Core in Action, 3e and Pro ASP.NET Core 7, Tenth Edition.
What should I know before learning PageModel?
Manning books that teach PageModel usually introduce dependency injection, loop and HTTP GET first.
What is the difference between PageModel and inject directive?
A PageModel is an ASP.NET Core Razor Pages class containing page state, data, and request-handling logic. The @inject directive is Razor markup that declares a service dependency and makes the resolved service available to a Razor view.
What is PageModel part of?
PageModel is part of Razor Pages. Razor Pages is an ASP.NET Core page-focused programming model in which independently addressable pages combine Razor markup with request-handling logic.
What are the parts of PageModel?
PageModel includes handler.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

