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 →
What to know first
- handlerA handler is a software routine or component invoked to process an event, request, message, or other input.
- model bindingModel binding is the process of locating incoming data, converting it to appropriate types, and assigning it to application objects or handler parameters.
- Model–view–controllerModel–view–controller is a software architectural pattern that separates application data and behavior, presentation, and interaction handling into model, view, and controller responsibilities.
- Razor PagesRazor Pages is an ASP.NET Core page-focused programming model in which independently addressable pages combine Razor markup with request-handling logic.
Related concepts
- Razor Pagesconfigures · Razor Pages is an ASP.NET Core page-focused programming model in which independently addressable pages combine Razor markup with request-handling logic.
- directivekind of · A directive is a framework-specific instruction attached to markup that controls processing, rendering, or the behavior of an element or template.
- 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 path pattern, often containing parameters, that an application uses to match requests to handlers or operations.
- routingconfigures · Routing is the process of directing an item, request, or task to a destination or processing path according to relevant rules or characteristics.
- URL patternuses · A URL pattern is a routing specification that determines which incoming URL or request a handler or destination matches.
Questions about page directive
What is page directive?
The @page directive is a Razor directive that identifies a file as a routable Razor Page.
Which Manning books explain page directive?
Pro ASP.NET Core 7, Tenth Edition and ASP.NET Core in Action, 3e.
What should I know before learning page directive?
Manning books that teach page directive usually introduce handler, model binding, Model–view–controller and Razor Pages first.
What is page directive a kind of?
Page directive is a kind of directive. 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.

