views:

937

answers:

1

Can someone explain the best way to handle this approach.

I am using TinyMCE editor. The information typed into this is loaded into a XDocument and then written to the database as a string by doing XDocument.ToString()

When I output the content to a webpage I load the string from the database into a XDocument, find the element and do a Html.Encode to write out.

When the data gets put into the database it gets put in this format <p><em>TEST</em>999</p>

When I retrieve it from the XDocument and do a Html.Encode it actually writes to the page

<p><em>TEST</em>999</p>

Obviously this is not what I want, it shouldn't write the HTML to the page for the user to see.

What is the best approach to take. Do a Decode/Encode before it gets put into the database? The Decode/Encode methods confuse me cause I'm not sure what they actually do.

Any help appreciated.

+1  A: 

HTMLEncode is used to encode HTML content to show in browser. This means if you want to display <b> (not bold content) you can use HTML encode to display it. HTMLDecode decodes the string that encoded.

In your case, you don't need to encode or decode your content. Because TinyMCE editor gives the content in HTML format, and you want to display the HTML applied content.

Canavar