This happens because there is a subtle difference between
<div>@index</div>
and
<AnyBlazorComponent>@index</AnyBlazorComponent>
In the first case Blazor immediately outputs the <div>
and index. In the second case a component is instantiated and a RenderFragment is created for @index
to set its ChildContent
. This captures @index
by reference. During rendering @index
contains the last value as a result.