The @page directive marks a .cshtml file as a routable Razor Page. It must be the first line; without it, ASP.NET Core ignores the file as a Razor Page and does not expose an endpoint. section 13.1.3 section 13.5
Use the directive to control how a Razor Page is reached:
- Write @page alone to use the default route derived from the file’s location, such as Pages/Privacy.cshtml mapping to /Privacy. section 13.1.3 section 13.5
- Append a relative route template, such as @page "Extra" or @page "{category}/{name}", to add segments or route parameters. section 14.4.1
- Start the template with / to replace the default route completely, such as @page "/checkout". section 14.4.2
A minimal Razor Page
Place the directive first, then associate the view with its PageModel and render ordinary HTML. The page below uses the default /Privacy route and displays a title from ViewData. section 13.1.3
Listing 13.3 The Privacy.cshtml Razor Page
@page #1
@model PrivacyModel #2
@{
ViewData["Title"] = "Privacy Policy"; #3
}
<h1>@ViewData["Title"]</h1> #4
<p>Use this page to detail your site's privacy policy.</p> #5
Inspect the complete Privacy.cshtml listing, including the directive, PageModel association, C# block, and dynamic HTML. section 13.1.3

