31

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.

0

3 Answers 3

55

Try this:

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

More info here.

Sign up to request clarification or add additional context in comments.

3 Comments

this doesn't work for Razor, for Razor use @Html.Raw(System.Web.HttpUtility.HtmlDecode(Model.yourhtmlvalue))
Checking the date of my answer .. it was PRE Razor :P
Thanks for bringing the date to my attention Pure, I have quoted just for somebody's info, its true Razor was not in existence when u posted your answer.
52

The answer provided by Pure.Krome is flawless for MVC2, but consider Razor syntax:

@Html.Raw(System.Web.HttpUtility.HtmlDecode(Model.yourEncodedHtmlFromYourDatabase))

Alternatively,

@Html.Raw(Server.HtmlDecode(Model.yourEncodedHtmlFromYourDatabase))

1 Comment

How can I make it so to be a link text
2

You want to use @Html.Raw(str).

See MSDN for more information.

Returns markup that is not HTML encoded.

This method wraps HTML markup using the IHtmlString class, which renders unencoded HTML.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.