liveBook · Manning

_ViewImports.cshtml

_ViewImports.cshtml is a Razor file whose namespaces and directives are implicitly available to views and pages in its directory scope.

How 2 Manning books explain it

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

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.