本文介绍了ASP.Net 4.0的回发TinyMCE的和XML编码重新连接codes含量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于ASP.NET 4.0的CMS,这里我使用通过jQuery TinyMCE的(3.4)编辑一个TextBox。

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

除了这个,我还有其它的文本框。
也有页,它控制的ContentType另一个下拉列表。
这种控制已启用的AutoPostBack并设置有关selectes项目文本框的可见性。

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.

因为我想继续回发确认上我已经配置使用XML的内容序列化(编码:XML)的TinyXML的。

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

现在我有这个问题,当从例如回传下拉列表occures,重恩codeS的内容。

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

我已经启用通过CSS原来的textarea的,这似乎是TinyMCS的保存方法的问题。
是否有人有一个解决方案,如何与TinyMCE的自定义save_callback也许解决这个问题?

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?

推荐答案

我刚刚与TinyMCE的和Asp.NET MVC类似的问题。在我的情况正在发生的事情是:

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


  1. 表单提交和TinyMCE的HTML EN codeS的内容(我用的是编码:XML选项)

  2. 在我的服务器端动作后,我去html的code我想允许(例如简化的标记:德codedHtml = model.HtmlContent.Replace(&放大器; LT; p&放大器; GT;,&LT; p&gt;中))。然后保存到数据库等之后,我去codeD HTML更新model.HtmlContent( model.HtmlContent =去codedHtml

  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)

但在这一点TinyMCE的编辑器,是显示了EN codeD的HTML,即&放大器; LT; P&放大器; GT;测试&放大器; LT; / P&放大器; GT; 而不是&LT; p&GT;测试&LT; / p&GT; ,即使我做了 model.HtmlContent =去codedHtml 在我的职务行为。实际发生的事情是asp.net忽略回发模型中的值,而是绑定公布值(见这里的关于如何工作的更多细节)。

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.

因此​​,在我的情况下,这个问题是没有什么实际的TinyMCE的,但同程表职位asp.net的MVC工作。希望这可以帮助别人。

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.

这篇关于ASP.Net 4.0的回发TinyMCE的和XML编码重新连接codes含量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 21:01