The ViewStart file

The Razor Pages _ViewStart.cshtml file contains code that is executed at the start of each Razor Page's execution. The ViewStart file affects all Razor Pages located in the same folder as the ViewStart file or any of its subfolders. ViewStart files are hierarchical. Those located in subfolders will be executed after those located higher up the file system hierarchy.

The most common use for the ViewStart file is to set the layout page for each Razor Page. Since the ViewStart file is a Razor Page, server-side code must be located in a Razor code block:

    Layout = "_Layout";
Last updated: 29/03/2018 22:53:33

On this page

© 2018 - 2024 - Mike Brind.
All rights reserved.
Contact me at