开发者

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

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<开发者_Go百科/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?


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>");


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.


Does a look at the entity_encoding setting help?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜