From 4224dfa6622c39b60fb1e43f322948633cdfe7f4 Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Fri, 5 Jul 2019 12:15:40 -0500 Subject: [PATCH] Blazor example update (#13129) --- aspnetcore/blazor/components.md | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/aspnetcore/blazor/components.md b/aspnetcore/blazor/components.md index 39c9734b16..f80b49955f 100644 --- a/aspnetcore/blazor/components.md +++ b/aspnetcore/blazor/components.md @@ -5,7 +5,7 @@ description: Learn how to create and use Razor components, including how to bind monikerRange: '>= aspnetcore-3.0' ms.author: riande ms.custom: mvc -ms.date: 07/01/2019 +ms.date: 07/05/2019 uid: blazor/components --- # Create and use ASP.NET Core Razor components @@ -955,34 +955,34 @@ The descendent `Tab` components capture the containing `TabSet` as a cascading p Render fragments can be defined using Razor template syntax. Razor templates are a way to define a UI snippet and assume the following format: ```cshtml -@... +@<{HTML tag}>... ``` -The following example illustrates how to specify `RenderFragment` and `RenderFragment` values. - -`RazorTemplates` component: +The following example illustrates how to specify `RenderFragment` and `RenderFragment` values and render templates directly in a component. Render fragments can also be passed as arguments to [templated components](#templated-components). ```cshtml -@{ - RenderFragment template = @

The time is @DateTime.Now.

; - RenderFragment petTemplate = (pet) => @

Your pet's name is @pet.Name.

; +@timeTemplate + +@petTemplate(new Pet { Name = "Rex" }) + +@code { + private RenderFragment timeTemplate = @

The time is @DateTime.Now.

; + private RenderFragment petTemplate = + (pet) => @

Your pet's name is @pet.Name.

; + + private class Pet + { + public string Name { get; set; } + } } ``` -Render fragments defined using Razor templates can be passed as arguments to templated components or rendered directly. For example, the previous templates are directly rendered with the following Razor markup: +Rendered output of the preceding code: -```cshtml -@template +```html +

The time is 10/04/2018 01:26:52.

-@petTemplate(new Pet { Name = "Rex" }) -``` - -Rendered output: - -``` -The time is 10/04/2018 01:26:52. - -Your pet's name is Rex. +

Your pet's name is Rex.

``` ## Manual RenderTreeBuilder logic @@ -1002,7 +1002,7 @@ Consider the following `PetDetails` component, which can be manually built into @code { [Parameter] - string PetDetailsQuote { get; set; } + private string PetDetailsQuote { get; set; } } ```