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/components/index.md
+44Lines changed: 44 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1624,6 +1624,50 @@ Rendered output of the preceding code:
1624
1624
<p>Pet: Nutty Rex</p>
1625
1625
```
1626
1626
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
+
1627
1671
## Static assets
1628
1672
1629
1673
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