_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 →
What to know first
- HTMLHTML is the standard markup language for structuring content and elements in documents on the web.
- Razor PagesRazor Pages is an ASP.NET Core page-focused programming model in which independently addressable pages combine Razor markup with request-handling logic.
- Tag HelpersTag Helpers are ASP.NET Core components that process HTML-like elements during Razor view or page rendering.
Related concepts
- Pages folderpart of · The Pages folder is the conventional ASP.NET Core project directory that contains Razor Pages and their supporting Razor configuration files.
- Razor syntaxconfigures · Razor syntax is a templating syntax that combines markup with embedded .NET code and directives to generate web content.
- Razor using directiveuses · A Razor using directive imports a namespace so its types can be referenced without namespace qualification in a Razor file.
- Tag Helpersconfigures · Tag Helpers are ASP.NET Core components that process HTML-like elements during Razor view or page rendering.
- @addTagHelper directivehas part · The @addTagHelper directive makes specified Tag Helpers available for processing in Razor views or pages.
- namespaceconfigures · A global namespace is a top-level naming context that binds identifiers defined at the outermost level and distinguishes them from names in nested scopes.
Questions about _ViewImports.cshtml
What is _ViewImports.cshtml?
_ViewImports.cshtml is a Razor file whose namespaces and directives are implicitly available to views and pages in its directory scope.
Which Manning books explain _ViewImports.cshtml?
Pro ASP.NET Core 7, Tenth Edition and ASP.NET Core in Action, 3e.
What should I know before learning _ViewImports.cshtml?
Manning books that teach _ViewImports.cshtml usually introduce HTML, Razor Pages and Tag Helpers first.
What is _ViewImports.cshtml part of?
_ViewImports.cshtml is part of Pages folder. The Pages folder is the conventional ASP.NET Core project directory that contains Razor Pages and their supporting Razor configuration files.
What are the parts of _ViewImports.cshtml?
_ViewImports.cshtml includes @addTagHelper directive.
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.

