Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an equivalent to Html.Raw in Blazor?

Tags:

blazor

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

like image 811
Dave Avatar asked May 30 '18 12:05

Dave


People also ask

How to render raw HTML in Blazor?

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.

What is the raw HTML?

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.


1 Answers

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.

like image 190
Maxim Kornilov Avatar answered Sep 18 '22 17:09

Maxim Kornilov