_ViewImports.cshtml
_ViewImports.cshtml is a Razor file whose namespaces and directives are implicitly available to views and pages in its directory scope.
Pro ASP.NET Core 7, Tenth Edition
A Razor view imports file, typically _ViewImports.cshtml, declares namespaces and other directives available to Razor views in its scope.
- How it is used
- Shares namespace imports and tag-helper registration across MVC views or Razor Pages.
- How deep it goes
- Works through file placement, three directives, and their effects on type names and tag-helper availability; leaves tag-helper implementation to separate treatment.
- Examples
- Uses Views and Pages imports files, a shortened @model declaration, a partial-view tag helper, and project-defined view-component tag helpers.
- What you can do after
- Operate/configure it to shorten Razor type references and enable built-in or application tag helpers across the intended views or pages.
Read how Pro ASP.NET Core 7, Tenth Edition explains _ViewImports.cshtml →
ASP.NET Core in Action, 3e
_ViewImports.cshtml is a conventionally named Razor file whose directives and imports are implicitly applied to Razor views and pages in its directory and descendant directories.
- How it is used
- Centralizes shared Razor directives and Tag Helper registrations across views, pages, partial views, and descendant folders.
- How deep it goes
- Defines supported directives, placement, hierarchy, and the boundary with _ViewStart.cshtml, but does not execute arbitrary C#.
- Examples
- Uses namespace imports, built-in Tag Helpers, and custom Tag Helper registration as concrete configuration examples.
- What you can do after
- Configure shared Razor namespaces and Tag Helpers without repeating directives in individual views.
Read how ASP.NET Core in Action, 3e explains _ViewImports.cshtml →
Related concepts
- Razor syntaxconfigures · Razor syntax is a templating syntax that combines markup with embedded .NET code and directives to generate web content.
- Tag Helpersconfigures · Tag Helpers are ASP.NET Core components that process HTML-like elements during Razor view or page rendering.
- Razor using directiveuses · A Razor using directive imports a namespace so its types can be referenced without namespace qualification in a Razor file.
- Pages folderpart of · The Pages folder is the conventional ASP.NET Core project directory that contains Razor Pages and their supporting Razor configuration files.
- namespaceconfigures · A namespace is a naming context or identifier space in which names are defined and resolved, distinguishing them from names in other contexts.
- @addTagHelper directivehas part · The @addTagHelper directive makes specified Tag Helpers available for processing in Razor views or pages.
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.

