RazorComponentResult rendering behavior (#31425)

pull/31427/head
Luke Latham 2024-01-11 09:39:36 -05:00 committed by GitHub
parent 0880da0a6a
commit d30224014d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 0 deletions

View File

@ -829,6 +829,17 @@ public IResult GetWelcomeComponent()
}
```
Only HTML markup for the rendered component is returned. Layouts and HTML page markup aren't automatically rendered with the component. To produce a complete HTML page, the app can maintain a [Blazor layout](xref:blazor/components/layouts) that provides HTML markup for `<html>`, `<head>`, `<body>`, and other tags. The component includes the layout with the [`@layout`](xref:mvc/views/razor#layout) Razor directive at the top of the component definition file, `Welcome.razor` for the example in this section. The following example assumes that the app has a layout named `RazorComponentResultLayout` (`Components/Layout/RazorComponentResultLayout.razor`):
```razor
@using BlazorSample.Components.Layout
@layout RazorComponentResultLayout
```
You can avoid placing the `@using` statement for the `Layout` folder in individual components by moving it to the app's `_Imports.razor` file.
For more information, see <xref:blazor/components/layouts>.
## Component namespaces
When using a custom folder to hold the project's Razor components, add the namespace representing the folder to either the page/view or to the `_ViewImports.cshtml` file. In the following example: