Skip to content

Commit 47dff80

Browse files
authored
Document multiple elements return in Razor delegate (#36488)
1 parent 3c3d46e commit 47dff80

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

aspnetcore/blazor/components/index.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,50 @@ Rendered output of the preceding code:
16241624
<p>Pet: Nutty Rex</p>
16251625
```
16261626

1627+
When the Razor delegate must return more than one HTML element, wrap the result in a `<text>` tag for an [explicit delimited transition](xref:mvc/views/razor#explicit-delimited-transition):
1628+
1629+
```razor
1630+
@RenderTwoElements()
1631+
1632+
<h2>ReturnIf</h2>
1633+
@ReturnIf()
1634+
1635+
<h2>ReturnForeach</h2>
1636+
@ReturnForeach()
1637+
1638+
@code {
1639+
private bool showTrueStatement = true;
1640+
1641+
private RenderFragment RenderTwoElements() =>
1642+
@<text>
1643+
<h2>Render Two Elements</h2>
1644+
@ChildFragment
1645+
</text>;
1646+
1647+
private RenderFragment ChildFragment => @<p>This is a paragraph.</p>;
1648+
1649+
private RenderFragment ReturnIf() =>
1650+
@<text>
1651+
@if (showTrueStatement)
1652+
{
1653+
<p>This is true!</p>
1654+
}
1655+
else
1656+
{
1657+
<p>This is false!</p>
1658+
}
1659+
</text>;
1660+
1661+
private RenderFragment ReturnForeach() =>
1662+
@<text>
1663+
@foreach (var item in new[] { 1, 2, 3 })
1664+
{
1665+
<p>Item: @item</p>
1666+
}
1667+
</text>;
1668+
}
1669+
```
1670+
16271671
## Static assets
16281672

16291673
Blazor follows the convention of ASP.NET Core apps for static assets. Static assets are located in the project's [`web root` (`wwwroot`) folder](xref:fundamentals/index#web-root) or folders under the `wwwroot` folder.

0 commit comments

Comments
 (0)