I have some HTML that is stored in a string. How can I render it in a Blazor/Razor view without automatic HTML encoding?
Raw HTML can be rendered in Blazor by using the MarkupString. You can set the raw HTML as a string to any parameter and cast it in a markup string.
The Raw HTML Content Type allows you to manually enter HTML code as content on the page. This Content Type would be useful if you are knowledgeable in HTML and want full control over the content that is produced.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With