Display encoded html with razor

jani picture jani · Feb 17, 2011 · Viewed 120.3k times · Source

I store encoded HTML in the database.

The only way i could display it correctly is :

<div class='content'>    
   @MvcHtmlString.Create(HttpUtility.HtmlDecode(Model.Content));
</div>

It's ugly. Is there any better way to do this?

Answer

Amitabh picture Amitabh · Feb 17, 2011

Try this:

<div class='content'>    
   @Html.Raw(HttpUtility.HtmlDecode(Model.Content))
</div>