Chris Marisic's challenge:
If Chris Marisic wants to update his comment to an answer, I will give him cookies.
I decided the following:
Ajax Form:
<div id="ajaxEditor"> @using (Ajax.BeginForm(MVC.Admin.StepEditor.Edit(), new AjaxOptions { UpdateTargetId = "ajaxEditor", HttpMethod = "POST", OnComplete="ReBindCKEditor" }, new { @name = "EditStepForm", @id = "EditStepForm" })) { <div class="editor-label"> @Html.LabelFor(model => model.StepText) </div> <div class="editor-field"> @Html.TextAreaFor(model => model.StepText, 20, 68, null) @Html.ValidationMessageFor(model => model.StepText) </div> } </div>
JavaScript:
As the error returns (see the answer to the question by Chris Marisich) it says that the CKEDITOR instance already exists, I need to get rid of it. So:
function BindCKEditor() { var elem = $('#StepText'); elem.ckeditor(function () {}, { toolbar: [ ['Source'], ['Preview'], ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Scayt'], ['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'], ['Image', 'Table', 'HorizontalRule'], ['Styles', 'Format'], ['Bold', 'Italic', 'Strike'], ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'], ['Link', 'Unlink', 'Anchor'] ] }); }
BindCKEditor () just does what it says on a can. He customizes the editor and applies it.
Now when I overwrite the text area with ajax response, I need to delete this instance and recreate it. So:
function ReBindCKEditor() { delete CKEDITOR.instances['StepText']; BindCKEditor(); }
Note that I am using ReBindCKEditor () in OnComplete for Ajax Form. I use oncomplete, not onsuccess, because I want it to rebuild regardless of success or another ajax call.
SUCCESS:
I can not recommend ckeditor highly enough. I thought it would be a nightmare to solve, but as soon as I sat down and put aside such thoughts, I found that there was very concise documentation and good user forums.
I looked through many other Rich Text Editors and none of them were so good or supported. Yahoo looked good, but was a nightmare and poor documentation unless you are a javascript expert that I don't know.
I almost went with lwrte, it looked good, but there was no support.
I looked at another, which remains unnamed.
But ckEditor really impressed me. Now I can roll it where I want, without fear or trepidation.
Note:
I do not work for CKEditor and have no connection with them. This is real enthusiasm. Yes, such a thing exists.