xwrs
xwrs

Reputation: 1297

WYSIWYG editors after postback

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?

Upvotes: 0

Views: 1455

Answers (2)

xwrs
xwrs

Reputation: 1297

Another way is to remove CKEDITOR.config.htmlEncodeOutput = true; and set [AllowHtml] attribute to Description property in this case.

Upvotes: 0

Paul Alexander
Paul Alexander

Reputation: 32367

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

tinyMCE.init({
        ...
        forced_root_block : null
});

Upvotes: 3

Related Questions