_ViewStart.cshtml sets a default layout for Razor views, so individual views can contain only their own content instead of repeating an HTML document or a Layout assignment. The layout supplies shared markup and inserts the view’s content at @RenderBody(). section 22.4.2 section 7.1.6
Set the default for controller views
Create Views/_ViewStart.cshtml containing `@{ Layout = "_Layout"; }`. Create Views/Shared/_Layout.cshtml with the common HTML document and `@RenderBody()` where view content belongs. A view such as Views/Shared/Common.cshtml can then contain just its own markup. In Visual Studio, the Razor View Start template creates the file; in Visual Studio Code, add it manually. section 22.4.2 section 7.1.6
Choose the file location and override only when needed:
- Put _ViewStart.cshtml in Pages to set a default for Razor Pages. Pages have their own configuration files, so their default can differ from the controller views’ default. section 8.2.1
- Put another view start file in Views/[controller] when every action of one controller needs a different layout. section 22.4.3
- Assign Layout in an individual view to select a different layout, including one chosen by an expression. Set `Layout = null;` when the view or page supplies its own complete HTML document. section 22.4.3 section 23.5.1
Do not confuse _ViewStart.cshtml with _ViewImports.cshtml. The former selects a default layout; the latter makes namespaces and tag helpers available without repeating their directives in each view or page. section 32.5 section 32.6
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<h6 class="bg-primary text-white text-center m-2 p-2">Layout</h6>
<!DOCTYPE html>
<html>
<head>
<link href="/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<h6 class="bg-secondary text-white text-center m-2 p-2">Products</h6>
<div class="m-2">
<table class="table table-sm table-striped table-bordered">
<thead><tr><th>Name</th><th>Price</th></tr></thead>
<tbody>
<!-- ...table rows omitted for brevity... >
</tbody>
</table>
</div>
</body>
</html>
</body>
</html>
Inspect the response with a full HTML view and an active default layout: the resulting document contains nested document structure. Set Layout to null in that view instead. section 22.4.3

