Page directive
The @page directive is a Razor directive that identifies a file as a routable Razor Page.
Pro ASP.NET Core 7, Tenth Edition
The @page directive is a Razor directive that assigns one or more URL routes to a Razor component or page.
- How it is used
- Directs requests to Razor Pages and selects Razor components for declared URLs.
- How deep it goes
- Works through file-based routes, explicit patterns, multiple routes, and segment values; defers detailed model binding.
- Examples
- Uses an Index.cshtml product lookup, administration URLs, and a person component with an id segment.
- What you can do after
- Build it from scratch: assign and verify routes for Razor Pages and components, including URL segment values.
Read how Pro ASP.NET Core 7, Tenth Edition explains page directive →
ASP.NET Core in Action, 3e
The @page directive is a Razor directive that marks a .cshtml file as a routable Razor Page.
- How it is used
- Marks .cshtml files as routable Razor Pages and customizes their route templates.
- How deep it goes
- Explains placement, default routing, appended segments, parameters, and replacement templates, while deferring additional-route preservation.
- Examples
- Uses Privacy.cshtml, Extra, category and name parameters, and checkout route templates.
- What you can do after
- Operate/configure Razor Page endpoints by registering pages and defining default, relative, or absolute route templates.
Read how ASP.NET Core in Action, 3e explains page directive →
Related concepts
- Razor Pagesused by · Razor Pages is an ASP.NET Core page-focused programming model in which independently addressable pages combine Razor markup with request-handling logic.
- URL patternuses · A URL pattern is a routing specification that determines which incoming URL or request a handler or destination matches.
- routingconfigures · Routing is the selection of a path, destination, or processing component to direct an item, request, or flow toward an intended endpoint.
- Razor componentconfigures · A Razor component is a reusable user-interface unit defined with Razor markup and .NET code that can render content and handle interactions.
- route templateconfigures · A route template is a URL or URI path pattern containing fixed segments and parameters that determines which requests an endpoint matches.
- directivekind of · A directive is a framework-specific instruction attached to markup that controls processing, rendering, or the behavior of an element or template.
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.

