CKEditor and MVC

I included ckeditor in the asp.net MVC project. My problem is that the input is encoded back to the controller, and then when it is replayed in the view, the content contains encoded characters and html tags.

How to show internal html and still have encoded text.

Any suggestions would be appreciated.

+4
source share
3 answers

What do you use for rendering textarea? If you use the Html helper (for example, Html.Textarea), the encoding is done automatically.

Therefore, if you use RTE, such as CKEditor or TinyMCE, you probably do not want this. So, just write the text box manually in the view or better yet write your own Textarea extension method to limit / exclude encoding.

+1
source

is there any reason you can't just use <% =%> instead of the <%:%> tags for your RTE output?

+1
source

I integrated CKeditor

<script type="text/javascript"> $(document).ready(function () { CKEDITOR.replaceByClassEnabled = true; $('textarea.editor-basic, textarea.editor-standard, textarea.editor-richtext, textarea.editor-full').each(function (i, textarea) { var config = {}; if ($(textarea).hasClass('editor-basic')) { config = { language: 'en', toolbar: [ { name: 'basicstyles', items: ['Source', 'RemoveFormat'] } ] }; } else if ($(textarea).hasClass('editor-standard')) { config = { language: 'en', toolbar: [ { name: 'basicstyles', items: ['Source', 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat'] } ] }; } else if ($(textarea).hasClass('editor-richtext')) { config = { language: 'en', toolbar: [ { name: 'basicstyles', items: ['Source', 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat'] }, '/', { name: 'colors', items: ['TextColor', 'BGColor', 'Maximize', 'ShowBlocks'] }, '/', { name: 'fonts', items: ['Link', 'Styles', 'Format', 'Font', 'FontSize'] } ] }; } else if ($(textarea).hasClass('editor-full')) { config = { language: 'en', height: '500px', toolbar: [ { name: 'document', items: ['Source', '-', 'Save', 'NewPage', 'DocProps', 'Preview', 'Print', '-', 'Templates'] }, { name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'] }, { name: 'editing', items: ['Find', 'Replace', '-', 'SelectAll', '-', 'SpellChecker', 'Scayt'] }, '/', { name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat'] }, { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl'] }, { name: 'links', items: ['Link', 'Unlink', 'Anchor'] }, { name: 'insert', items: ['Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar'] }, { name: 'styles', items: ['Styles', 'Format', 'Font', 'FontSize'] }, { name: 'colors', items: ['TextColor', 'BGColor', 'Maximize', 'ShowBlocks'] } ] }; } else { return; } CKEDITOR.replace(textarea.id, config); }); $('textarea.editor-basic, textarea.editor-standard, textarea.editor-richtext, textarea.editor-full').each(function (i, textarea) { if (!$(textarea).hasClass('langdefault')) { $('#cke_' + textarea.id).hide(); } }); $('.sort_up, .sort_down').click(function () { var thisrow = $(this).parent().parent().parent(); if ($(this).hasClass('sort_down')) { if (thisrow.next().find('.sort_up').length > 0) { thisrow.next().after(thisrow); } } else { if (thisrow.prev().find('.sort_up').length > 0) { thisrow.prev().before(thisrow); } } thisrow.parent().find('tr').removeClass('alternate-row'); thisrow.parent().find('tr:odd').addClass('alternate-row'); updateOrders(); return false; }); $('.sortable').tableDnD({ onDrop: function (table, row) { $(table).find('tr').removeClass('alternate-row'); $(table).find('tr:odd').addClass('alternate-row'); updateOrders(); } }); $(".form-reset").bind("click", function () { $("input[type='text'], textarea").val(""); for (var i in CKEDITOR.instances) { CKEDITOR.instances[i].setData(""); } }); }); </script> <!-- in view page --> <textarea name="desc" id="desc" class="form-textarea2 editor-basic"><%=Html.Encode(ViewBage.desc) %></textarea> 
0
source

All Articles