All Razor files end with .cshtml. Most Razor files are intended to be browsable and contain a mixture of client-side and server-side code, which, when processed, results in HTML being sent to the browser. These pages are usually referred to as "content pages". Other Razor files have a leading underscore (
_) in their file name. These files are not intended to be browsable. The leading underscore is often used for naming partial pages, but three files named in this way have a particular function within a Razor Pages application.
The _Layout.cshtml file acts a template for all content pages that reference it. Consistent part of a site's design are declared in the _Layout.cshtml file. These can include the header, footer, site navigation and so on. Typically, the _Layout.cshtml file also includes the
The _ViewStart.cshtml file contains code that executes after the code in any content page in the same folder or any child folders. It provides a convenient location to specify the layout file for all content pages that are affected by it, and that is typically what you see in the _ViewStart.cshtml file that comes with any Razor Pages (or MVC) template.
The purpose of the _ViewImports.cshtml file is to provide a mechanism to make directives available to Razor pages globally so that you don't have to add them to pages individually.
The default Razor Pages template includes a _ViewImports.cshtml file in the Pages folder - the root folder for Razor pages. All Razor pages in the folder heirarchy will be affected by the directives set in the _ViewImports.cshtml file.