Is there an equivalent to Html.Raw in Blazor?

Dave picture Dave · May 30, 2018 · Viewed 14.5k times · Source

I have some HTML that is stored in a string. How can I render it in a Blazor/Razor view without automatic HTML encoding?

Answer

Maxim Kornilov picture Maxim Kornilov · Jul 30, 2018

Feature to render raw HTML was added in Blazor 0.5.0 version. This is the example of how raw HTML can be rendered from string containing HTML content:

@((MarkupString)myMarkup)

@functions {
    string myMarkup = "<p class='markup'>This is a <em>markup string</em>.</p>";
}

More info can be found in "Blazor 0.5.0 experimental release now available" announcement.