簡體   English   中英

ASP.NET MVC上的CKEditor-如何編輯文檔

[英]CKEditor on ASP.NET MVC - how to edit a document

我已經找到了很多有關如何在ASP.NET MVC上設置CKEditor的教程,但是它們主要集中在如何創建文檔上。 我不僅需要創建,還需要編輯文檔。

我使用基本的剃刀動作來創建文本區域,

@Html.TextAreaFor(model => model.Description)

和基本的javascript來設置編輯器。

CKEDITOR.replace('Description', {
        language: 'cs'
    });

但是,我的編輯器加載為空白。 始終,即使model.Description已經包含一些文本。 添加setData函數只會使Rich Text編輯器消失,並用HTML加載文本區域(已轉義,如我在源代碼中所述)。 我的問題是:

  1. 如何設置要在編輯器中編輯的文本?
  2. 有沒有更有效的方法或更好的編輯器來處理此問題?

您不需要#。 你使用jQuery嗎? 嘗試這個:

$(document).ready(function() {
    // Get the description element to check it exists and that it has a value
    var d = $('#Description');
    alert(d.val(););

    // Create the editor
    CKEDITOR.replace('Description', {
        language: 'en'
    });
});

如果您不使用jquery,請嘗試以下操作:

function replaceCke(){
    // Get the description element to check it exists and that it has a value
    var d = document.getElementById("Description");
    alert(d.value);

    // Create the editor
    CKEDITOR.replace('Description', {
        language: 'en'
    });
}

if(window.addEventListener) {
    window.addEventListener('load', replaceCke, false);
} else {
    window.attachEvent('onload', replaceCke);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM