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

Why do Blazor render fragments render out of sequence with surrounding HTML components?

$
0
0

I have a simple Blazor project that contains a home page and a reference to Razor component library. The component contains a RenderFrament that is inserted in a <table> element, but the resulting HTML does not reflect this.

The project has a home page:

@page "/"<Grid Data="_data"><Rows Context="context">        @context.Name</Rows></Grid>@code {    private List<Item> _data = null!;    private class Item    {        public string Description { get; set; } = null!;        public string Name { get; set; } = null!;        public static Item Placeholder() => new() { Description = "foo", Name = "bar" };    }    protected override void OnInitialized()    {        _data = [Item.Placeholder(), Item.Placeholder()];    }}

And a reference to a Razor component library with the following files:Grid.razor

@typeparam T<table>    @if (Data is not null)    {        @foreach (T row in Data)        {            @Rows(row)        }    }</table>

Grid.razor.cs

using Microsoft.AspNetCore.Components;public partial class Grid<T> : ComponentBase{    [Parameter, EditorRequired]    public List<T>? Data { get; set; }    [Parameter, EditorRequired]    public required RenderFragment<T> Rows { get; set; }}

The resulting HTML is

<body>    barbar<table></table></body>

Why is barbar not contained in the <table> component?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



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