Reputation: 155
I have found a lot of tutorials on how to setup CKEditor on ASP.NET MVC, but they were mostly focused on how to create documents. I need not only to create, but to edit documents as well.
I use a basic razor action to create a textarea,
@Html.TextAreaFor(model => model.Description)
and basic javascript to setup the editor.
CKEDITOR.replace('Description', {
language: 'cs'
});
However, my editor loads blank. Always, even if model.Description contains already some text. Add the setData function only made the Rich text editor disappear and loaded the textarea with HTML (escaped, as I checked in the source). My questions are:
Upvotes: 0
Views: 2173
Reputation: 13402
You don't need #. Do you use jquery? Try this:
$(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'
});
});
If you don't use jquery, try this:
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);
}
Upvotes: 1