The @model directive declares the PageModel type associated with a Razor Page. Place it after @page, typically on the first lines of the .cshtml file, so ASP.NET Core knows which PageModel to use. section 13.1.3 section 17.2.1
Associate a page with its PageModel
A Privacy.cshtml page can declare @model PrivacyModel. The corresponding PrivacyModel class is conventionally defined in Privacy.cshtml.cs. A ToDoItem page similarly uses @model ToDoItemModel. section 13.1.3 section 17.2.1
The directive determines how Razor Pages process a request:
- After routing selects a Razor Page, the framework reads @model to choose the associated PageModel. section 17.2.1
- The selected PageModel supplies strongly typed public properties that the Razor view can use to generate HTML. section 17.5
- The framework can bind [BindProperty] properties and execute a page handler appropriate to the request’s HTTP verb. section 17.2.1
- A PageModel and @model directive are optional; without them, the framework can execute an implicit handler and render the view directly. section 17.2.1
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 example, including @page, @model PrivacyModel, ViewData, and rendered markup. section 13.1.3

