Members of the component class are defined in one or more @code blocks. In @code blocks.
Component members are used in rendering logic using C# expressions that start with the @ symbol. For example, a C# field is rendered by prefixing @ to the field name.(more info)
The RenderFragment delegate must accept a parameter called __builder of type RenderTreeBuilder so that the Razor compiler can produce rendering instructions for the fragment.
Sample1:
@using Microsoft.AspNetCore.Components.Rendering
@{ load1(__builder); }
@code {
void load1(RenderTreeBuilder __builder)
{
@for (int i = 0; i < 1; i++)
{
<div class="alert-info">
<h3>This is the number @i</h3>
</div>
}
}
}
Sample2:
<button class="btn btn-success" @onclick="()=>Calc()">Action</button>
@((MarkupString)myMarkup)
@code {
string myMarkup = "";
void Calc()
{
@for (int j = 0; j < 55; j++)
{
myMarkup += getMarkup(j);
}
}
string getMarkup(int j) {
var myMarkup = "<div class='alert-info'>";
myMarkup += $"<h3>This is the number {j}</h3>";
myMarkup += "</div>";
return myMarkup;
}
}