回发后所见即所得的编辑器
我尝试向我的页面添加不同的所见即所得编辑器。如果我正在保存,然后尝试编辑我的记录,那么一切都可以。但是,如果在编辑页面上我为某些记录的字段设置了无效值并提交,则 ckeditor/tinymce 包含带有周围 标记的编码 html。如果我再次提交表单,那么我的 wisiwyg 编辑器将包含编码的先前值,并由附加的
标签包围。等等。
我的编辑页面元素
...
@Html.EditorFor(m => m.Description)
...
<script type="text/javascript">
CKEDITOR.replace('Description');
CKEDITOR.config.htmlEncodeOutput = true;
</script>
我的描述属性在
...
private string _description;
public string Description
{
get
{
return HttpUtility.HtmlDecode(_description);
}
set
{
_description = value;
}
}
...
如何使所见即所得编辑器在 ModelState.IsValid==false
时正确加载属性值?
I tried to add different wysiwyg editors to my page. If I'm saving, and then trying to edit my record, then everything is ok. But if on the edit page I set invalid value to some record's field and submit then ckeditor/tinymce contains encoded html with surrounding <p></p>
tags. If I submit the form again, then my wisiwyg editor contains encoded previous value, surrounded by additional <p></p>
tags. And so on.
My edit page elements
...
@Html.EditorFor(m => m.Description)
...
<script type="text/javascript">
CKEDITOR.replace('Description');
CKEDITOR.config.htmlEncodeOutput = true;
</script>
My Description property in
...
private string _description;
public string Description
{
get
{
return HttpUtility.HtmlDecode(_description);
}
set
{
_description = value;
}
}
...
How to make wysiwyg editors to load property value properly when ModelState.IsValid==false
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从版本 3.0a1 开始,使用 TinyMCE 进行编辑时,如果正在编辑的 HTML 没有根块元素(div、p、table 等),那么它将自动换行内容。您可以通过设置
forced_root_block
属性来禁用此功能。摘自http://www.tinymce.com/wiki.php/Configuration:forced_root_block
As of version 3.0a1, when editing with TinyMCE if the HTML being edited does not have a root block element (div, p, table, etc.) then it will wrap the contents automatically. You can disable this feature by setting the
forced_root_block
property.Excerpt from http://www.tinymce.com/wiki.php/Configuration:forced_root_block
在这种情况下,另一种方法是删除
CKEDITOR.config.htmlEncodeOutput = true;
并将[AllowHtml]
属性设置为Description
属性。Another way is to remove
CKEDITOR.config.htmlEncodeOutput = true;
and set[AllowHtml]
attribute toDescription
property in this case.