I do not create Classic Editor, I use Decoupled Editor. I did as you advised.
This is why the community asks for the source code. There are several CKEditor 5 default builds each use the same API. Since the decoupled-document build uses the Decoupled Editor, I'll use the decoupled-document build in the example.
I have this error in the console:
The error message indicates "editor" is not initialized or pointing to the right place. I assume there is a bug in your code which we cannot see.
@{
ViewData["Title"] = "Index";
}
<h1>Document editor</h1>
<div id="toolbar-container"></div>
<div id="editor">
<p>This is the initial editor content.</p>
</div>
<div>
<button id="submitButton" type="button">Submit</button>
</div>
@section scripts {
<script src="https://cdn.ckeditor.com/ckeditor5/38.1.1/decoupled-document/ckeditor.js"></script>
<script>
let decoupledEditor;
DecoupledEditor
.create(document.querySelector('#editor'))
.then(editor => {
const toolbarContainer = document.querySelector('#toolbar-container');
toolbarContainer.appendChild(editor.ui.view.toolbar.element);
decoupledEditor = editor;
})
.catch(error => {
console.error(error);
});
document.querySelector('#submitButton').addEventListener('click', () => {
const editorData = decoupledEditor.getData();
console.log(editorData);
});
</script>
}