Asp.net mvc CKEditor与MVC

Asp.net mvc CKEditor与MVC,asp.net-mvc,ckeditor,Asp.net Mvc,Ckeditor,我已将ckeditor集成到MVC asp.net项目中。我的问题是,输入被编码回控制器,然后在视图中重新显示时,内容包含编码字符&html标记 如何显示内部html并对文本进行编码 如果您有任何建议,我们将不胜感激。您使用什么来呈现文本区域?如果您使用的是Html助手(例如Html.Textarea),则编码将自动完成 因此,如果您使用像CKEditor或TinyMCE这样的RTE,您可能不希望这样。因此,只需在视图中手动写出一个textarea,或者最好编写您自己的textarea扩展方法来

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

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


如果您有任何建议,我们将不胜感激。

您使用什么来呈现文本区域?如果您使用的是Html助手(例如Html.Textarea),则编码将自动完成


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

您为什么不能在RTE输出中使用标签而不是标签?

我已与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>

$(文档).ready(函数(){
CKEDITOR.replaceByClassEnabled=true;
$('textarea.editor-basic,textarea.editor-standard,textarea.editor-richtext,textarea.editor-full')。每个(函数(i,textarea){
var config={};
if($(textarea).hasClass('editor-basic')){
配置={
语言:"en",,
工具栏:
[
{name:'basicstyles',项:['Source','RemoveFormat']}
]
};
}
else if($(textarea).hasClass('editor-standard')){
配置={
语言:"en",,
工具栏:
[
{name:'basicstyles',项:['Source','Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat']}
]
};
}
else if($(textarea).hasClass('editor-richtext')){
配置={
语言:"en",,
工具栏:
[
{name:'basicstyles',项:['Source','Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat']},
'/',
{name:'colors',项:['TextColor','BGColor','Maximize','ShowBlocks']},
'/',
{name:'Font',项:['Link','style','Format','Font','FontSize']}
]
};
}
else if($(textarea).hasClass('editor-full')){
配置={
语言:"en",,
高度:“500px”,
工具栏:
[
{name:'document',项:['Source','-','Save','NewPage','DocProps','Preview','Print','-','Templates']},
{name:'clipboard',项:['Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo']},
{name:'editing',项:['Find','Replace','-','SelectAll','-','SpellChecker','Scayt']},
'/',
{name:'basicstyles',项:['Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat'],
{
名称:“段落”,项目:['NumberedList'、'BulletedList'、'-'、'Outdent'、'Indent'、'-'、'Blockquote'、'CreateDiv',
“-”、“JustifyLeft”、“justifCenter”、“justifRight”、“JustifyBlock”、“wistifBlock”、“BidiLtr”、“BidiRtl”]
},
{name:'links',项:['Link','Unlink','Anchor']},
{name:'insert',项:['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar']},
{name:'styles',items:['styles','Format','Font','FontSize']},
{name:'colors',项:['TextColor','BGColor','Maximize','ShowBlocks']}
]
};
}
否则{
返回;
}
CKEDITOR.replace(textarea.id,config);
});
$('textarea.editor-basic,textarea.editor-standard,textarea.editor-richtext,textarea.editor-full')。每个(函数(i,textarea){
if(!$(textarea).hasClass('langdefault')){
$('#cke'+textarea.id).hide();
}
});
$('.sort\u up、.sort\u down')。单击(函数(){
var thisrow=$(this.parent().parent().parent();
if($(this).hasClass('sort_down')){
if(thisrow.next().find('.sort_up').length>0){
thisrow.next().after(thisrow);
}
}
否则{
if(thisrow.prev().find('.sort_up')。长度>0){
thisrow.prev().before(thisrow);
}
}
thisrow.parent().find('tr').removeClass('alternate-row');
thisrow.parent().find('tr:odd').addClass('alternate-row');
updateOrders();
返回false;
});
$('.sortable').tableDnD({
onDrop:函数(表、行){
$(表).find('tr').removeClass('alternate-row');
$(表).find('tr:odd').addClass('alternate-row');
updateOrders();
}
});
$(“.form reset”).bind(“单击”),函数(){
$(“输入[type='text'],textarea”).val(“”);
for(CKEDITOR.instances中的变量i){
CKEDITOR.instances[i].setData(“”);
}
});
});