How to display HTML stored in a database from an ASP.NET MVC view?

Jedidja picture Jedidja · Nov 18, 2008 · Viewed 50k times · Source

I have HTML code edited by FCKEditor stored in a database and would like to display (well render) it onto a view. So, for instance, something stored as:

<>pre<>This is some sample text<>pre</&gt

Will be displayed to the user as:

This is some sample text

(With the appropriate style for pre-formatted-text)

The view already has the required string to display from ViewData, I'm just not sure what the best way to show it to the user is.

Answer

Pure.Krome picture Pure.Krome · Nov 18, 2008

try

<%= System.Web.HttpUtility.HtmlDecode(yourEncodedHtmlFromYouDatabase) %>

more info here @ MSDN online.

hth!