You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/blazor/integrate-components.md
+38-18Lines changed: 38 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ description: Learn about data binding scenarios for components and DOM elements
5
5
monikerRange: '>= aspnetcore-3.1'
6
6
ms.author: riande
7
7
ms.custom: mvc
8
-
ms.date: 04/01/2020
8
+
ms.date: 04/14/2020
9
9
no-loc: [Blazor, SignalR]
10
10
uid: blazor/integrate-components
11
11
---
@@ -15,7 +15,14 @@ By [Luke Latham](https://github.com/guardrex) and [Daniel Roth](https://github.c
15
15
16
16
Razor components can be integrated into Razor Pages and MVC apps. When the page or view is rendered, components can be prerendered at the same time.
17
17
18
-
## Prepare the app to use components in pages and views
18
+
After [preparing the app](#prepare-the-app), use the guidance in the following sections depending on the app's requirements:
19
+
20
+
* Routable components – For components that are directly routable from user requests. Follow this guidance when visitors should be able to make an HTTP request in their browser for a component with an [`@page`](xref:mvc/views/razor#page) directive.
21
+
*[Use routable components in a Razor Pages app](#use-routable-components-in-a-razor-pages-app)
22
+
*[Use routable components in an MVC app](#use-routable-components-in-an-mvc-app)
23
+
*[Render components from a page or view](#render-components-from-a-page-or-view)– For components that aren't directly routable from user requests. Follow this guidance when the app embeds components into existing pages and views with the [Component Tag Helper](xref:mvc/views/tag-helpers/builtin-th/component-tag-helper).
24
+
25
+
## Prepare the app
19
26
20
27
An existing Razor Pages or MVC app can integrate Razor components into pages and views:
21
28
@@ -72,7 +79,7 @@ An existing Razor Pages or MVC app can integrate Razor components into pages and
72
79
73
80
To support routable Razor components in Razor Pages apps:
74
81
75
-
1. Follow the guidance in the [Prepare the app to use components in pages and views](#prepare-the-app-to-use-components-in-pages-and-views) section.
82
+
1. Follow the guidance in the [Prepare the app](#prepare-the-app) section.
76
83
77
84
1. Add an *App.razor* file to the project root with the following content:
78
85
@@ -139,15 +146,15 @@ To support routable Razor components in Razor Pages apps:
139
146
...
140
147
```
141
148
142
-
For more information on namespaces, see the [Component namespaces](#component-namespaces) section.
149
+
For more information on namespaces, see the [Component namespaces](#component-namespaces) section.
143
150
144
151
## Use routable components in an MVC app
145
152
146
153
*This section pertains to adding components that are directly routable from user requests.*
147
154
148
155
To support routable Razor components in MVC apps:
149
156
150
-
1. Follow the guidance in the [Prepare the app to use components in pages and views](#prepare-the-app-to-use-components-in-pages-and-views) section.
157
+
1. Follow the guidance in the [Prepare the app](#prepare-the-app) section.
151
158
152
159
1. Add an *App.razor* file to the root of the project with the following content:
153
160
@@ -178,6 +185,19 @@ To support routable Razor components in MVC apps:
178
185
```
179
186
180
187
Components use the shared *_Layout.cshtml* file for their layout.
188
+
189
+
<xref:Microsoft.AspNetCore.Mvc.Rendering.RenderMode> configures whether the `App` component:
190
+
191
+
* Is prerendered into the page.
192
+
* Is rendered as static HTML on the page or if it includes the necessary information to bootstrap a Blazor app from the user agent.
193
+
194
+
| Render Mode | Description |
195
+
| ----------- | ----------- |
196
+
|<xref:Microsoft.AspNetCore.Mvc.Rendering.RenderMode.ServerPrerendered>| Renders the `App` component into static HTML and includes a marker for a Blazor Server app. When the user-agent starts, this marker is used to bootstrap a Blazor app. |
197
+
|<xref:Microsoft.AspNetCore.Mvc.Rendering.RenderMode.Server>| Renders a marker for a Blazor Server app. Output from the `App` component isn't included. When the user-agent starts, this marker is used to bootstrap a Blazor app. |
198
+
|<xref:Microsoft.AspNetCore.Mvc.Rendering.RenderMode.Static>| Renders the `App` component into static HTML. |
199
+
200
+
For more information on the Component Tag Helper, see <xref:mvc/views/tag-helpers/builtin-th/component-tag-helper>.
181
201
182
202
1. Add an action to the Home controller:
183
203
@@ -209,7 +229,19 @@ To support routable Razor components in MVC apps:
209
229
...
210
230
```
211
231
212
-
For more information on namespaces, see the [Component namespaces](#component-namespaces) section.
232
+
For more information on namespaces, see the [Component namespaces](#component-namespaces) section.
233
+
234
+
## Render components from a page or view
235
+
236
+
*This section pertains to adding components to pages or views, where the components aren't directly routable from user requests.*
237
+
238
+
To render a component from a page or view, use the [Component Tag Helper](xref:mvc/views/tag-helpers/builtin-th/component-tag-helper).
239
+
240
+
For more information on how components are rendered, component state, and the `Component` Tag Helper, see the following articles:
0 commit comments