How to transform a string into HTML C#

Asked

Viewed 777 times

4

I am using a component and need to load it with HTML snippet that comes in a variable. For this I created this Jquery:

$(document).ready(function(){
    $('.mentions-kinder').html('@HttpUtility.HtmlDecode(Model.FormulaRecover)');
});

But still when I spin it, it doesn’t load the code, and it goes like this:

Foto 1

If Jquery read the code like the above print would work, but the code when I inspect the page looks like this:

$(document).ready(function(){
    $('.mentions-kinder').html('<span class="mention badge badge-warning" contenteditable="false" serialized-mention="[#Quantidade de Visitas](tag:12)"><span class="tag-trigger">Parametro: </span><span class="tag-value">Quantidade de Visitas</span><span class="delete-mention tag-delete"><i class="icon-remove"></i></span></span> <span class="mention badge badge-primary" contenteditable="false" serialized-mention="(area:104)"><span class="area-trigger">Area: </span><span class="area-value">Alessandro Spricigo</span><span class="delete-mention area-delete"><i class="icon-remove"></i></span></span> *');
});

And it all goes wrong. Any idea for this ?

1 answer

5


When you have a string of html it is not rendered in DOM, why this string can be render it is necessary to call the method Html.Raw() passing to string html. The method Html.Raw() Transforms the string on an appointment html.

Solution

In your case you should use as below:

@Html.Raw(HttpUtility.HtmlDecode(Model.FormulaRecover))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.