Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor syntax for Renderfragment literal without 'root container'

$
0
0

In a Blazor component, when there is some html that repeats but it's not complex enough to justify the creation of one extra component, I put this html into a RenderFragmet private field or function, so I can reuse it along the component. A simplified example:

<ul>    @menuOption("Menu 1")    @menuOption("Menu 2")    @menuOption("Menu 3")</ul>@code {    private RenderFragment menuOption(string title) =>        @<li class="text-lg font-bold bg-blue-500 px-4 py-2">@title</li>;}

But I don't know how to write the RenderFragment literal if there is no 'root element' for the RenderFragment. For example, in React I can do:

const fragment = <><div>1</div><div>2</div><div>3</div></>;

but in Blazor I can't do:

private RenderFragment fragment = @<><div>1</div><div>2</div><div>3</div></>;

Is there something similar in Blazor?

Regards.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>