ASP.Net 4.0 with TinyMCE and XML Encoding Transcodes Content to Postback

I have an ASP.NET 4.0 based CMS where I use TinyMCE (3.4) through jQuery to edit a single text field.

In addition to this, I have several other text fields. There is also another DropDown list on the page that controls the Contenttype. This control has AutoPostback turned on and sets the visibility of the text fields associated with the selectes element.

As I want to keep checking after feedback, I configured TinyXML to use xml to serialize the content (encoding: "xml").

Now I have a problem when the postback from, for example, the DropDown List, transcodes the contents.

Init: "Hallo" 1st Postback: "<p>Hallo</p>" 2nd Postback: "<p>&lt;p&gt;Hallo&lt;/p&gt;</p>" 

I have included the source text area via css, and this seems to be a problem with the TinyMCS Save method. Does anyone have a solution how to fix this problem, maybe using the special save_callback on TinyMCE?

+6
jquery tinymce postback
source share
3 answers

Could it be that the data is reloaded into the tinymce window after it is saved?

When I came across this before in TinyMCE / WebForms, it can be easily fixed by decoding the data before filling out the form field and after postback:

TextAreaID.Text = Server.HtmlDecode ("<p> hello </p>");

+1
source share

I had a similar problem with Tinymce and Asp.NET MVC. In my case, the following happened:

  • The form is submitted and tinymce html encodes the content (I use the encoding: 'xml' parameter encoding: 'xml' )
  • In my server side post post action, I am decoding the html tags that I want to allow (a simplified example: decodedHtml = model.HtmlContent.Replace("&lt;p&gt;", "<p>") ). Then after saving to the database, etc. I am updating model.HtmlContent with decoded html ( model.HtmlContent = decodedHtml )

but at that moment the tinymce editor was showing encoded html, i.e. &lt;p&gt;test&lt;/p&gt; instead of <p>test</p> , although I did model.HtmlContent = decodedHtml in my post action. Actually, asp.net ignores the value in the model during postback and instead binds the published value (see here http://weblog.west-wind.com/posts/2012/Apr/20/ASPNET-MVC-Postbacks- and-HtmlHelper-Controls-ignoring-Model-Changes for more information on how this works).

There is a way to do this in your mail action

 ModelState.Remove("HtmlContent"); 

and then binds the value in your view model instead of the published value.

So, in my case, the problem was not related to tinim, but with how form messages work in asp.net mvc. Hope this helps someone.

+1
source share

Have a look at entity_encoding help?

0
source share

All Articles