Raw HTML can be rendered in Blazor by using MarkupString. You can define the property and pass it to a parameter by using MarkupString.
[Index.razor]
@page "/"
<button class='btn btn-primary' @onclick="OnClickButtonEvent">Counter</button>
@((MarkupString)MyMarkup)
@code {
private int count = 0;
public string MyMarkup;
public void OnClickButtonEvent()
{
++count;
MyMarkup = "<div>Current count: <span style=\"color:red\"><b>" + @count + "</b></span></div>";
}
}
Share with