4

我已将 ckeditor 集成到 MVC asp.net 项目中。我的问题是输入被编码回控制器,然后在视图中重新显示时,内容包含编码字符和 html 标签。

如何显示内部 html 并仍然对文本进行编码。

任何建议,将不胜感激。

4

3 回答 3

1

你用什么来渲染textarea?如果您使用 Html 帮助程序(例如 Html.Textarea),则编码会自动完成。

因此,如果您使用的是 CKEditor 或 TinyMCE 之类的 RTE,您可能不希望这样。因此,只需在视图中手动写出一个 textarea,或者更好地编写自己的 Textarea 扩展方法来限制/消除编码。

于 2009-10-13T14:44:40.970 回答
1

为什么您不能只使用 <%=%> 而不是 <%:%> 标记用于 RTE 输出?

于 2011-02-04T09:20:59.263 回答
0

我已与 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>
于 2017-05-24T09:11:35.620 回答