I guess the child content of the RadzenCard is only getting the parameter set when the loop has finished? If this is the case, how do I achieve the desired effect so I can set the child content in a loop?
Hi Paul,
Thanks for your reply. That is interesting and addresses the issue. I would be interested to know how the behaviour is different when written like this. Could you enlighten me?
To be honest, I wouldn't pretend to know this and can only give my assumption.
I think it has to do with the asynchronous nature of Blazor. If the system thinks it can get away with running two seemingly separate processes at the same time it will. So I think adding the variable declaration forces it to account for the loop at each iteration and not let the contents of the loop run separately.
Again, my best guess. If anyone has any further information on this, I too would be very interested to know what's going on under the hood.
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.