ASP.Net 4.0 with TinyMCE and XML Encoding re-encodes Content on Postback

◇◆丶佛笑我妖孽 提交于 2019-12-21 12:38:08

问题


i have a ASP.NET 4.0 based CMS, where i use the TinyMCE (3.4) via jQuery to edit one Textbox.

In addition to this i have several other textboxes. There is also another DropDown List on the Page, which controls the Contenttype. This Control has AutoPostback enabled and sets the visibility on the textboxes regarding the selectes item.

As i want to keep the Postback Validation on i have configured the TinyXML to use xml for the content serialisation (encoding: "xml").

Now i have the problem, when a postback from e.g. the DropDown List occures, the re-encodes the content.

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

i have enabled the original textarea via css and this seems to be a problem of the TinyMCS's Save method. Does anybody have a solution, how to fix this issue maybe with a custom save_callback on the TinyMCE?


回答1:


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

When I encountered this before in TinyMCE/WebForms, it was easily fixed by decoding the data before populating the form field and after postbacks:

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




回答2:


I have just had a similar problem with Tinymce and Asp.NET MVC. In my case what was happening was:

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

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

A way around this is in your post action to do

ModelState.Remove("HtmlContent");

and then it will bind the value in your view model instead of the posted value.

So in my case, the issue wasn't actually with tinymce but with the way form posts work in asp.net mvc. Hope this helps someone.




回答3:


Does a look at the entity_encoding setting help?



来源:https://stackoverflow.com/questions/4748786/asp-net-4-0-with-tinymce-and-xml-encoding-re-encodes-content-on-postback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!