_ViewImports.cshtml holds Razor directives shared by views or pages. Put it in Views for MVC controller views, or in Pages for Razor Pages. It saves repeating namespace imports and tag-helper registration in individual .cshtml files. The leading underscore distinguishes this supporting file from a view returned to the user. section 21.3.1 section 25.2.2
Add the directives needed by the views or pages:
- @using imports a namespace so a view can write @model Product instead of @model WebApp.Models.Product. It also keeps other Razor type references shorter. section 21.3.1
- @namespace sets the namespace of generated Razor Page classes. When that namespace matches the page model class, @model IndexModel can replace its fully qualified name. section 23.4.1
- @addTagHelper registers tag helpers. Its arguments select helper classes, optionally with a wildcard, and name their assembly. Add it to one .cshtml file for that file alone, or to _ViewImports.cshtml for wider availability. section 25.2.2
A Pages imports file
In Pages/_ViewImports.cshtml, use @namespace WebApp.Pages, @using WebApp.Models, and @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers. A page can then declare @model IndexModel without its namespace and use the built-in partial tag helper to include a shared view. Restart the application and request /index to check the page; shortening the model name does not change its response. section 23.4.1 section 23.5.2
Keep Views and Pages imports separate when an application uses both MVC and Razor Pages. To make project-defined tag helpers available in both, add @addTagHelper *, WebApp to each imports file; the built-in helpers use Microsoft.AspNetCore.Mvc.TagHelpers as the assembly name. Do not confuse imports with _ViewStart.cshtml: view start selects a default layout, while imports supplies directives. section 25.2.2 section 7.1.6

