We can create elements dynamically in server-side Blazor applications by following this example.
@page "/render-fragment"
<button type="button" @onclick="@RenderComponent">
Trigger rendering
</button>
@DynamicFragment
@code {
private string dynamicContent = "This is a long text...";
private RenderFragment DynamicFragment;
private RenderFragment CreateComponent() => builder =>
{
dynamicContent = dynamicContent.Replace("long", "long long");
builder.OpenElement(1, "p");
builder.AddContent(2, dynamicContent);
builder.CloseElement();
};
private void RenderComponent()
{
DynamicFragment = CreateComponent();
}
}
Reference link
Share with