Model directive
The @model directive is a Razor directive that declares the model type associated with a page or view.
Pro ASP.NET Core 7, Tenth Edition
The Razor model directive declares the .NET type of the view model exposed to a Razor view.
- How it is used
- Declares the model type a Razor view expects, or selects the page model class in a Razor Page.
- How deep it goes
- Explains generated `RazorPage<T>`, editor and build-time checking, nullable view data, view imports, and the distinct Razor Page use.
- Examples
- Uses product-detail and product-list views, a product table-row partial, and a Razor Page that displays a loaded product.
- What you can do after
- Apply it in CSHTML to type-check model expressions and distinguish controller-view models from Razor Page models.
Read how Pro ASP.NET Core 7, Tenth Edition explains model directive →
ASP.NET Core in Action, 3e
The @model directive is a Razor directive that declares the PageModel type associated with a Razor Page.
- How it is used
- Declares the PageModel type that a Razor Page uses to handle requests and provide strongly typed data to its view.
- How deep it goes
- Explains placement, type association, request processing, binding, and handler execution, while deferring PageModel details.
- Examples
- Uses PrivacyModel and ToDoItemModel declarations, including the conventional .cshtml.cs code-behind pairing.
- What you can do after
- Apply the directive to associate a Razor Page with a PageModel and access its typed properties during HTML generation.
Read how ASP.NET Core in Action, 3e explains model directive →
Related concepts
- directivekind of · A directive is a framework-specific instruction attached to markup that controls processing, rendering, or the behavior of an element or template.
- subtemplateconfigures · A subtemplate is a reusable template fragment that can be rendered independently or included within another template to produce part of an output.
- PageModelconfigures · A PageModel is an ASP.NET Core Razor Pages class containing page state, data, and request-handling logic.
- view modelconfigured by · A view model is a data structure that supplies a user-interface view with the data required to render a particular output.
- asp-for attributeused by · The asp-for attribute is an ASP.NET Core Razor attribute that associates an HTML element with a model property for Tag Helper processing.
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.

