EdCharbeneau / BlazorProSnippets

A collection of Blazor snippets for .NET ninjas.
Other
23 stars 4 forks source link

Snippet for RenderFragment<T> templates #5

Closed EdCharbeneau closed 4 years ago

EdCharbeneau commented 4 years ago

Example

@typeparam TItem

<table class="table">
    <thead>
        <tr>@TableHeader</tr>
    </thead>
    <tbody>
        @foreach (var item in Items)
        {
            <tr>@RowTemplate(item)</tr>
        }
    </tbody>
    <tfoot>
        <tr>@TableFooter</tr>
    </tfoot>
</table>

@code {
    [Parameter]
    public RenderFragment TableHeader { get; set; }

    [Parameter]
    public RenderFragment<TItem> RowTemplate { get; set; }

    [Parameter]
    public RenderFragment TableFooter { get; set; }

    [Parameter]
    public IReadOnlyList<TItem> Items { get; set; }
}
EdCharbeneau commented 4 years ago

Added in 2.1