History in ASP.NET MVC DOCX Editor

27 Aug 20261 minute to read

The ASP.NET MVC DOCX Editor (Document Editor) tracks the history of all editing actions done in the document, which allows undo and redo functionality.

Enable or disable history

Inject the EditorHistory module in your application to provide history preservation functionality for DocumentEditor.

@Html.EJS().DocumentEditor("container").IsReadOnly(false).EnableEditor(true).EnableSelection(true).EnableSfdtExport(true).Render()

<script>
    var documenteditor;    
    document.addEventListener('DOMContentLoaded', function () {        
        documenteditor = document.getElementById("container").ej2_instances[0];
        documenteditor.enableEditorHistory = true;
    });
</script>

You can enable or disable history preservation for a DOCX Editor instance at any time using the enableEditorHistory property.

editor.enableEditorHistory = false;

Undo and redo

You can perform undo and redo by using the Ctrl+Z and Ctrl+Y keyboard shortcuts. The DOCX Editor exposes APIs to do it programmatically. To undo the last editing operation in the DOCX Editor, refer to the following sample code.

editor.editorHistory.undo();

To redo the last undone action, refer to the following code example.

editor.editorHistory.redo();

Stack size

The history of editing actions will be maintained in a stack, so that the last item will be reverted first. By default, the DOCX Editor limits the size of the undo and redo stacks to 500 each, respectively. However, you can customize this limit.

editor.editorHistory.undoLimit = 400;
editor.editorHistory.redoLimit = 400;

See Also