Skip to content

Commit d4d3760

Browse files
authored
Cross-link 9.0 sample code (#33872)
1 parent bc9fe76 commit d4d3760

27 files changed

+772
-78
lines changed

aspnetcore/blazor/advanced-scenarios.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ In <xref:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder> methods wi
3333

3434
`BuiltContent.razor`:
3535

36-
:::moniker range=">= aspnetcore-8.0"
36+
:::moniker range=">= aspnetcore-9.0"
37+
38+
:::code language="razor" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/Components/Pages/BuiltContent.razor":::
39+
40+
:::moniker-end
41+
42+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
3743

3844
:::code language="razor" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Components/Pages/BuiltContent.razor":::
3945

aspnetcore/blazor/blazor-ef-core.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ The sample demonstrates use of EF Core to handle optimistic concurrency. However
6262

6363
The sample uses a local [SQLite](https://www.sqlite.org/index.html) database so that it can be used on any platform. The sample also configures database logging to show the SQL queries that are generated. This is configured in `appsettings.Development.json`:
6464

65-
:::moniker range=">= aspnetcore-8.0"
65+
:::moniker range=">= aspnetcore-9.0"
66+
67+
:::code language="json" source="~/../blazor-samples/9.0/BlazorWebAppEFCore/appsettings.Development.json":::
68+
69+
:::moniker-end
70+
71+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
6672

6773
:::code language="json" source="~/../blazor-samples/8.0/BlazorWebAppEFCore/appsettings.Development.json":::
6874

@@ -167,7 +173,13 @@ In the preceding factory:
167173

168174
The following example configures [SQLite](https://www.sqlite.org/index.html) and enables data logging. The code uses an extension method (`AddDbContextFactory`) to configure the database factory for DI and provide default options:
169175

170-
:::moniker range=">= aspnetcore-8.0"
176+
:::moniker range=">= aspnetcore-9.0"
177+
178+
:::code language="csharp" source="~/../blazor-samples/9.0/BlazorWebAppEFCore/Program.cs" id="snippet1":::
179+
180+
:::moniker-end
181+
182+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
171183

172184
:::code language="csharp" source="~/../blazor-samples/8.0/BlazorWebAppEFCore/Program.cs" id="snippet1":::
173185

@@ -207,7 +219,13 @@ In the home page of the sample app, `IDbContextFactory<ContactContext>` is injec
207219

208220
A `DbContext` is created using the factory (`DbFactory`) to delete a contact in the `DeleteContactAsync` method:
209221

210-
:::moniker range=">= aspnetcore-8.0"
222+
:::moniker range=">= aspnetcore-9.0"
223+
224+
:::code language="razor" source="~/../blazor-samples/9.0/BlazorWebAppEFCore/Components/Pages/Home.razor" id="snippet1":::
225+
226+
:::moniker-end
227+
228+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
211229

212230
:::code language="razor" source="~/../blazor-samples/8.0/BlazorWebAppEFCore/Components/Pages/Home.razor" id="snippet1":::
213231

@@ -274,7 +292,13 @@ You can use the factory to create a context and track it for the lifetime of the
274292

275293
The sample app ensures the context is disposed when the component is disposed:
276294

277-
:::moniker range=">= aspnetcore-8.0"
295+
:::moniker range=">= aspnetcore-9.0"
296+
297+
:::code language="csharp" source="~/../blazor-samples/9.0/BlazorWebAppEFCore/Components/Pages/EditContact.razor" id="snippet1":::
298+
299+
:::moniker-end
300+
301+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
278302

279303
:::code language="csharp" source="~/../blazor-samples/8.0/BlazorWebAppEFCore/Components/Pages/EditContact.razor" id="snippet1":::
280304

@@ -306,7 +330,13 @@ The sample app ensures the context is disposed when the component is disposed:
306330

307331
Finally, [`OnInitializedAsync`](xref:blazor/components/lifecycle) is overridden to create a new context. In the sample app, [`OnInitializedAsync`](xref:blazor/components/lifecycle) loads the contact in the same method:
308332

309-
:::moniker range=">= aspnetcore-8.0"
333+
:::moniker range=">= aspnetcore-9.0"
334+
335+
:::code language="csharp" source="~/../blazor-samples/9.0/BlazorWebAppEFCore/Components/Pages/EditContact.razor" id="snippet2":::
336+
337+
:::moniker-end
338+
339+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
310340

311341
:::code language="csharp" source="~/../blazor-samples/8.0/BlazorWebAppEFCore/Components/Pages/EditContact.razor" id="snippet2":::
312342

aspnetcore/blazor/components/cascading-values-and-parameters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ The following `ThemeInfo` C# class specifies the theme information.
111111

112112
:::moniker range=">= aspnetcore-9.0"
113113

114-
:::code language="csharp" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/ThemeInfo.cs":::
114+
:::code language="csharp" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/ThemeInfo.cs":::
115115

116116
:::moniker-end
117117

aspnetcore/blazor/file-downloads.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,13 @@ The following component:
110110
111111
`FileDownload1.razor`:
112112
113-
:::moniker range=">= aspnetcore-8.0"
113+
:::moniker range=">= aspnetcore-9.0"
114+
115+
:::code language="razor" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/Components/Pages/FileDownload1.razor":::
116+
117+
:::moniker-end
118+
119+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
114120
115121
:::code language="razor" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Components/Pages/FileDownload1.razor":::
116122
@@ -159,7 +165,13 @@ The example in this section uses a download file named `quote.txt`, which is pla
159165
160166
`wwwroot/files/quote.txt`:
161167
162-
:::moniker range=">= aspnetcore-8.0"
168+
:::moniker range=">= aspnetcore-9.0"
169+
170+
:::code language="text" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/wwwroot/files/quote.txt":::
171+
172+
:::moniker-end
173+
174+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
163175
164176
:::code language="text" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/wwwroot/files/quote.txt":::
165177
@@ -203,7 +215,17 @@ The following example component downloads the file from the same origin that the
203215
204216
`FileDownload2.razor`:
205217
206-
:::moniker range=">= aspnetcore-8.0"
218+
:::moniker range=">= aspnetcore-9.0"
219+
220+
:::code language="razor" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/Components/Pages/FileDownload2.razor":::
221+
222+
For interactive components, the button in the preceding example calls the `DownloadFileFromURL` handler to invoke the JavaScript (JS) function `triggerFileDownload`.
223+
224+
If the component adopts static server-side rendering (static SSR), add an event handler for the button ([`addEventListener` (MDN documentation)](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)) to call `triggerFileDownload` following the guidance in <xref:blazor/js-interop/ssr>.
225+
226+
:::moniker-end
227+
228+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
207229
208230
:::code language="razor" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Components/Pages/FileDownload2.razor":::
209231

aspnetcore/blazor/forms/binding.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,22 @@ The following example independently binds two forms to their models by form name
238238

239239
`Starship6.razor`:
240240

241+
:::moniker-end
242+
243+
:::moniker range=">= aspnetcore-9.0"
244+
245+
:::code language="razor" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/Components/Pages/Starship6.razor":::
246+
247+
:::moniker-end
248+
249+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
250+
241251
:::code language="razor" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Components/Pages/Starship6.razor":::
242252

253+
:::moniker-end
254+
255+
:::moniker range=">= aspnetcore-8.0"
256+
243257
## Nest and bind forms
244258

245259
The following guidance demonstrates how to nest and bind child forms.
@@ -248,26 +262,82 @@ The following ship details class (`ShipDetails`) holds a description and length
248262

249263
`ShipDetails.cs`:
250264

265+
:::moniker-end
266+
267+
:::moniker range=">= aspnetcore-9.0"
268+
269+
:::code language="csharp" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/ShipDetails.cs":::
270+
271+
:::moniker-end
272+
273+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
274+
251275
:::code language="csharp" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/ShipDetails.cs":::
252276

277+
:::moniker-end
278+
279+
:::moniker range=">= aspnetcore-8.0"
280+
253281
The following `Ship` class names an identifier (`Id`) and includes the ship details.
254282

255283
`Ship.cs`:
256284

285+
:::moniker-end
286+
287+
:::moniker range=">= aspnetcore-9.0"
288+
289+
:::code language="csharp" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/Ship.cs":::
290+
291+
:::moniker-end
292+
293+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
294+
257295
:::code language="csharp" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Ship.cs":::
258296

297+
:::moniker-end
298+
299+
:::moniker range=">= aspnetcore-8.0"
300+
259301
The following subform is used for editing values of the `ShipDetails` type. This is implemented by inheriting <xref:Microsoft.AspNetCore.Components.Forms.Editor%601> at the top of the component. <xref:Microsoft.AspNetCore.Components.Forms.Editor%601> ensures that the child component generates the correct form field names based on the model (`T`), where `T` in the following example is `ShipDetails`.
260302

261303
`StarshipSubform.razor`:
262304

305+
:::moniker-end
306+
307+
:::moniker range=">= aspnetcore-9.0"
308+
309+
:::code language="razor" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/Components/StarshipSubform.razor":::
310+
311+
:::moniker-end
312+
313+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
314+
263315
:::code language="razor" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Components/StarshipSubform.razor":::
264316

317+
:::moniker-end
318+
319+
:::moniker range=">= aspnetcore-8.0"
320+
265321
The main form is bound to the `Ship` class. The `StarshipSubform` component is used to edit ship details, bound as `Model!.Details`.
266322

267323
`Starship7.razor`:
268324

325+
:::moniker-end
326+
327+
:::moniker range=">= aspnetcore-9.0"
328+
329+
:::code language="razor" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/Components/Pages/Starship7.razor":::
330+
331+
:::moniker-end
332+
333+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
334+
269335
:::code language="razor" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Components/Pages/Starship7.razor":::
270336

337+
:::moniker-end
338+
339+
:::moniker range=">= aspnetcore-8.0"
340+
271341
## Initialize form data with static SSR
272342

273343
When a component adopts static SSR, the [`OnInitialized{Async}` lifecycle method](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) and the [`OnParametersSet{Async}` lifecycle method](xref:blazor/components/lifecycle#after-parameters-are-set-onparameterssetasync) fire when the component is initially rendered and on every form POST to the server. To initialize form model values, confirm if the model already has data before assigning new model values in `OnParametersSet{Async}`, as the following example demonstrates.

aspnetcore/blazor/forms/index.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,22 @@ Standard HTML forms are supported. Create a form using the normal HTML `<form>`
5050

5151
`StarshipPlainForm.razor`:
5252

53+
:::moniker-end
54+
55+
:::moniker range=">= aspnetcore-9.0"
56+
57+
:::code language="razor" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/Components/Pages/StarshipPlainForm.razor":::
58+
59+
:::moniker-end
60+
61+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
62+
5363
:::code language="razor" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Components/Pages/StarshipPlainForm.razor":::
5464

65+
:::moniker-end
66+
67+
:::moniker range=">= aspnetcore-8.0"
68+
5569
In the preceding `StarshipPlainForm` component:
5670

5771
* The form is rendered where the `<form>` element appears. The form is named with the [`@formname`](xref:mvc/views/razor#formname) directive attribute, which uniquely identifies the form to the Blazor framework.
@@ -84,10 +98,20 @@ A form is defined using the Blazor framework's <xref:Microsoft.AspNetCore.Compon
8498

8599
`Starship1.razor`:
86100

87-
:::moniker range=">= aspnetcore-8.0"
101+
:::moniker range=">= aspnetcore-9.0"
102+
103+
:::code language="razor" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/Components/Pages/Starship1.razor":::
104+
105+
:::moniker-end
106+
107+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
88108

89109
:::code language="razor" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Components/Pages/Starship1.razor":::
90110

111+
:::moniker-end
112+
113+
:::moniker range=">= aspnetcore-8.0"
114+
91115
In the preceding `Starship1` component:
92116

93117
* The <xref:Microsoft.AspNetCore.Components.Forms.EditForm> component is rendered where the `<EditForm>` element appears. The form is named with the [`@formname`](xref:mvc/views/razor#formname) directive attribute, which uniquely identifies the form to the Blazor framework.
@@ -158,7 +182,13 @@ In the next example, the preceding component is modified to create the form in t
158182

159183
`Starship2.razor`:
160184

161-
:::moniker range=">= aspnetcore-8.0"
185+
:::moniker range=">= aspnetcore-9.0"
186+
187+
:::code language="razor" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/Components/Pages/Starship2.razor":::
188+
189+
:::moniker-end
190+
191+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
162192

163193
:::code language="razor" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Components/Pages/Starship2.razor":::
164194

aspnetcore/blazor/forms/input-components.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ The following `Starship` type, which is used in several of this article's exampl
9696

9797
`Starship.cs`:
9898

99-
:::moniker range=">= aspnetcore-8.0"
99+
:::moniker range=">= aspnetcore-9.0"
100+
101+
:::code language="csharp" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/Starship.cs":::
102+
103+
:::moniker-end
104+
105+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
100106

101107
:::code language="csharp" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Starship.cs":::
102108

@@ -135,7 +141,13 @@ When the model property for the ship's classification (`Classification`) is set,
135141

136142
`Starship3.razor`:
137143

138-
:::moniker range=">= aspnetcore-8.0"
144+
:::moniker range=">= aspnetcore-9.0"
145+
146+
:::code language="razor" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/Components/Pages/Starship3.razor":::
147+
148+
:::moniker-end
149+
150+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
139151

140152
:::code language="razor" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Components/Pages/Starship3.razor":::
141153

@@ -236,7 +248,13 @@ In the following example:
236248

237249
`Starship4.razor`:
238250

239-
:::moniker range=">= aspnetcore-8.0"
251+
:::moniker range=">= aspnetcore-9.0"
252+
253+
:::code language="razor" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/Components/Pages/Starship4.razor":::
254+
255+
:::moniker-end
256+
257+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
240258

241259
:::code language="razor" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Components/Pages/Starship4.razor":::
242260

@@ -317,7 +335,13 @@ In the following example, the user must select at least two starship classificat
317335

318336
:::moniker-end
319337

320-
:::moniker range=">= aspnetcore-8.0"
338+
:::moniker range=">= aspnetcore-9.0"
339+
340+
:::code language="razor" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/Components/Pages/Starship5.razor":::
341+
342+
:::moniker-end
343+
344+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
321345

322346
:::code language="razor" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Components/Pages/Starship5.razor":::
323347

0 commit comments

Comments
 (0)