liveBook · Manning

Page directive

The @page directive is a Razor directive that identifies a file as a routable Razor Page.

How 2 Manning books explain it

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

Related concepts

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.