{
  "$schema": "https://ai.syncfusion.com/schema/registry-item.json",
  "name": "docx-editor-mail-merge",
  "framework": "aspnet-mvc",
  "type": "registry:component",
  "component": "DocxEditor",
  "variant": "mail-merge",
  "dependencies": [
    "Syncfusion.AspNetMvc.DocumentEditor",
    "Syncfusion.AspNetMvc.Lists",
    "Syncfusion.AspNetMvc.Popups"
  ],
  "description": "Document editor demonstrating mail merge fields populated with recipient data.",
  "meta": {
    "essentialStudioRelease": "2026 Volume 3 (v35.1.37)",
    "license": "commercial-or-community",
    "licenseNote": "The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md",
    "requiresLicenseKey": true,
    "requiresServerEndpoint": false,
    "platformIndex": "https://ai.syncfusion.com/aspnet-mvc/llms.txt",
    "skillPack": "syncfusion/aspnetmvc-ui-components-skills",
    "docs": "https://ai.syncfusion.com/gallery/aspnet-mvc/docx-editor-mail-merge.md"
  },
  "files": [
    {
      "target": "src/components/docx-editor-mail-merge/DocxEditor.cshtml",
      "content": "@using Syncfusion.EJ2\n@using Syncfusion.EJ2.Lists\n@section ControlsSection{\n    <div class=\"control-section\" id=\"target\">\n        <div id='documenteditor_titlebar' class=\"e-de-ctn-title\"></div>\n\n        <div class=\"col-lg-2 control-section\" style=\"padding-top: 5px;padding-right: inherit; padding-left: 5px;height:590px;border-left: 1px solid rgb(238, 238, 238);border-bottom: 1px solid rgb(238, 238, 238);\">\n            <h5><label style=\"display:block;margin:1px;padding-top: 5px\">Select Field to Insert</label></h5>\n            @Html.EJS().ListView(\"listview\").DataSource((IEnumerable<object>)ViewData[\"dataSource\"]).Fields(new ListViewFieldSettings { Tooltip = \"Category\" }).Render()\n        </div>\n        <div class=\"col-lg-10 control-section\" style=\"padding-left:0px;padding-right:0px;padding-top:0px;\">\n            <div style=\"height:590px\">\n                @Html.EJS().DocumentEditorContainer(\"container\").Height(\"590px\").EnableToolbar(true).Render()\n            </div>\n        </div>\n\n        @Html.EJS().Dialog(\"dialog\").Header(\"Merge Field\").Visible(false).FooterTemplate(\"<button id='addButton' class='e-control e-btn e-primary'>Insert</button><button id='cancelButton' class='e-control e-btn e-primary'>Cancel</button>\").ShowCloseIcon(true).Width(\"300px\").Target(\"#target\").IsModal(true).ContentTemplate(@<input id='inVal' class='e-input' type='text' placeholder='Type a field to insert Eg. FirstName' />).Render()\n        <div class=\"overlay\" id=\"popup-overlay\" style=\"display: none;\"></div>\n        <div id='waiting-popup' style=\"display: none;\">\n            <svg class=\"circular\" height=\"40\" width=\"40\" role=\"none\">\n                <circle class=\"circle-path\" cx=\"25\" cy=\"25\" r=\"20\" fill=\"none\" stroke-width=\"6\" stroke-miterlimit=\"10\" />\n            </svg>\n        </div>\n    </div>\n    <script src=\"~/Scripts/documenteditor/default-properties.js\"></script>\n}\n\n@section Scripts{\n    <script>\n     var documenteditor;\n     var contentChanged = false;\n     var listview = document.getElementById(\"listview\").ej2_instances[0];\n     var dialogBox = document.getElementById(\"dialog\").ej2_instances[0];\n     document.addEventListener('DOMContentLoaded', function () {\n         var documenteditorElement = document.getElementById(\"container\");\n         var container = documenteditorElement.ej2_instances[0];\n         container.documentEditorSettings.showRuler = true;\n         container.toolbarItems = [ 'New', 'Open', 'Separator', 'Undo',\n            'Redo',\n            'Separator',\n            {\n            prefixIcon: \"sf-icon-InsertMergeField\",\n            tooltipText: \"Insert Field\",\n            text: onWrapText(\"Insert Field\"),\n            id: \"InsertField\"\n             },\n             {\n\n             prefixIcon: \"sf-icon-FinishMerge\",\n             tooltipText: \"Insert Field\",\n             text: onWrapText(\"Merge Document\"),\n             id: \"MergeDocument\"\n             },\n             'Separator',\n            'Image',\n            'Table',\n            'Hyperlink',\n            'Bookmark',\n            'TableOfContents',\n            'Separator',\n            'Header',\n            'Footer',\n            'PageSetup',\n            'PageNumber',\n            'Break',\n            'Separator',\n            'Find',\n            'Separator',\n            'Comments',\n            'TrackChanges',\n            'Separator',\n            'LocalClipboard',\n            'RestrictEditing',\n            'Separator',\n            'FormFields',\n            'UpdateFields'\n             ];\n         container.toolbarClick = function (args) {\n             switch (args.item.id) {\n                 case 'MergeDocument':\n                     mergeDocument();\n                     break;\n                 case 'InsertField':\n                     showInsertFielddialog();\n                     break;\n             }\n         };\n         documenteditor = container.documentEditor;\n         documenteditorElement.ej2_instances[0].serviceUrl = window.baseurl + 'api/documenteditorservice/';\n         documenteditor.serviceUrl = window.baseurl + 'api/documenteditorservice/';\n         var ajax = new ej.base.Ajax(\"@Url.Content(\"~/scripts/documenteditor/data-mailmerge.json\")\", 'GET', true);\n         ajax.send().then();\n         ajax.onSuccess = function (data) {\n             documenteditor.open(data);\n             documenteditor.documentName = 'Mail Merge';\n             updateDocumentTitle();\n         };\n         titleBarDiv = document.getElementById('documenteditor_titlebar');\n         initComponentAndWireEvent();\n\n         container.documentChange = function () {\n             updateDocumentTitle();\n             documenteditor.focusIn();\n         };\n         // Add drag start element for list view\n         document.getElementById(\"listview\").addEventListener(\"dragstart\", function (event) {\n             event.dataTransfer.setData(\"Text\", event.target.innerText);\n             event.target.classList.add('de-drag-target');\n\n         });\n\n         // Prevent default drag over for document editor element\n         document.getElementById(\"container\").addEventListener(\"dragover\", function (event) {\n             event.preventDefault();\n         });\n\n\n         // Drop Event for document editor element\n         document.getElementById(\"container\").addEventListener(\"drop\", function (e) {\n             console.log(this);\n             var text = e.dataTransfer.getData('Text').replace(/\\n/g, '').replace(/\\r/g, '').replace(/\\r\\n/g, '');\n             documenteditor.selection.select({ x: e.offsetX, y: e.offsetY, extend: false });\n             container.documentEditor.editor.insertField('MERGEFIELD ' + text + ' \\\\* MERGEFORMAT');\n         });\n\n         document.addEventListener(\"dragend\", function (event) {\n             if (event.target.classList.contains('de-drag-target')) {\n                 event.target.classList.remove('de-drag-target');\n             }\n         });\n         function onWrapText(text) {\n        let content = '';\n        let index = text.lastIndexOf(' ');\n        content = text.slice(0, index);\n        text.slice(index);\n        content += '<div class=\"e-de-text-wrap\">' + text.slice(index) + '</div>';\n        return content;\n         }\n\n         //Click Event\n         listview.addEventListener(\"select\", function (args) {\n             var fieldName = args.text;\n             if (fieldName !== '') {\n                 container.documentEditor.editor.insertField('MERGEFIELD ' + fieldName + ' \\\\* MERGEFORMAT');\n             }\n             dialogBox.hide();\n             container.documentEditor.focusIn();\n         });\n\n\n        function showInsertFielddialog() {\n            dialogBox.show();\n        }\n        document.getElementById('addButton').onclick = function (e) {\n            addField();\n        };\n        document.getElementById('cancelButton').onclick = function (e) {\n            cancelDialog();\n        };\n\n        function addField() {\n            let fieldNameTextBox = document.getElementById('inVal');\n            var fieldName = fieldNameTextBox.value;\n            if (fieldName !== '') {\n                container.documentEditor.editor.insertField('MERGEFIELD ' + fieldName + ' \\\\* MERGEFORMAT');\n            }\n            dialogBox.hide();\n            container.documentEditor.focusIn();\n        };\n        function cancelDialog() {\n            var dialogBox = document.getElementById(\"dialog\").ej2_instances[0];\n            dialogBox.hide();\n        };\n\n\n         function mergeDocument() {\n             documenteditor.saveAsBlob(\"Docx\").then(function (blob) {\n                 var fileReader = new FileReader();\n                 fileReader.onload = function () {\n                     var base64String = fileReader.result;\n                     var data = {\n                         fileName: documenteditor.documentName + '.docx',\n                         documentData: base64String\n                     }\n                     showHideWaitingIndicator(true)\n                     var httpRequest = new XMLHttpRequest();\n                     httpRequest.open('Post', window.baseurl + 'api/documenteditorservice/MailMerge', true);\n                     httpRequest.setRequestHeader(\"Content-Type\", \"application/json;charset=UTF-8\");\n                     httpRequest.onreadystatechange = function () {\n                         if (httpRequest.readyState === 4) {\n                             if (httpRequest.status === 200 || httpRequest.status === 304) {\n                                 documenteditor.open(httpRequest.responseText);\n                             } else {\n                                 // Failed to merge document\n                                 ejs.popups.DialogUtility.alert({\n                        title: 'Information',\n                        content: 'Failed to merge document.',\n                        showCloseIcon: true,\n                        closeOnEscape: true,\n                    });\n                             }\n                             showHideWaitingIndicator(false);\n                         }\n                     };\n                     httpRequest.send(JSON.stringify(data));\n                 }\n                 fileReader.readAsDataURL(blob);\n             });\n         }\n     });\n        function showHideWaitingIndicator(show) {\n            document.getElementById(\"popup-overlay\").style.display = show ? 'block' : 'none';\n            document.getElementById(\"waiting-popup\").style.display = show ? 'block' : 'none';\n        }\n\n    </script>\n\n\n}\n\n\n<style>\n    #documenteditor_titlebar {\n        border-bottom: 1px solid #2B3481;\n        height: 36px;\n        line-height: 26px;\n        width: 100%;\n        font-size: 12px;\n        padding-left: 15px;\n        padding-right: 10px;\n        font-family: inherit;\n    }\n\n    #documenteditor_title_contentEditor {\n        height: 26px;\n        max-width: 85%;\n        width: auto;\n        overflow: hidden;\n        display: inline-block;\n        padding-left: 4px;\n        padding-right: 4px;\n        margin: 5px;\n    }\n\n    .overlay {\n        z-index: 10;\n        display: none;\n        position: absolute;\n        background-color: #383838;\n        height: 100%;\n        width: 100%;\n        opacity: .5;\n        left: 0;\n        top: 0;\n        bottom: 0;\n    }\n\n    #waiting-popup {\n        width: 56px;\n        height: 56px;\n        position: absolute;\n        top: calc(50% - 28px);\n        left: calc(50% - 28px);\n        border-radius: 50%;\n        padding: 3px;\n        overflow: hidden;\n        background-position: center;\n        background-color: white;\n        z-index: 20;\n        display: none;\n    }\n\n    .circular {\n        animation: rotate 2s linear infinite;\n        height: 50px;\n        width: 50px;\n        border-radius: 50%;\n    }\n\n    .circle-path {\n        stroke-dasharray: 1, 200;\n        stroke-dashoffset: 0;\n        animation: dash 1.5s ease-in-out infinite, color 6s ease-in-out infinite;\n        stroke-linecap: round;\n        stroke: #ff4081;\n    }\n\n    @@keyframes rotate {\n        100% {\n            transform: rotate(360deg);\n        }\n    }\n\n    @@keyframes dash {\n        0% {\n            stroke-dasharray: 1, 200;\n            stroke-dashoffset: 0;\n        }\n\n        50% {\n            stroke-dasharray: 89, 200;\n            stroke-dashoffset: -35;\n        }\n\n        100% {\n            stroke-dasharray: 89, 200;\n            stroke-dashoffset: -124;\n        }\n    }\n\n    .single-line {\n        cursor: text !important;\n        outline: none;\n    }\n\n    .heading-section {\n        padding-bottom: 20px;\n        padding-top: 20px;\n    }\n\n    .single-line:hover {\n        border-color: #e4e4e4 !important;\n    }\n\n    [contenteditable=\"true\"].single-line {\n        white-space: nowrap;\n        border-color: #e4e4e4 !important;\n    }\n\n    /** Document editor sample level font icons*/\n\n    @@font-face {\n        font-family: 'Sample brower icons';\n        font-weight: normal;\n        font-style: normal;\n    }\n\n    [class^=\"e-de-icon-\"],\n    [class*=\" e-de-icon-\"] {\n        font-family: 'Sample brower icons' !important;\n    }\n\n    .e-de-icon-Print:before {\n        content: \"\\e723\";\n    }\n\n    .e-de-icon-Download:before {\n        content: \"\\e728\";\n    }\n\n    .e-btn-hide {\n        display: none;\n    }\n\n    .Table {\n        border-collapse: separate;\n        border-spacing: 10px;\n        width: 85%;\n        margin: 0px -5px 0px;\n    }\n\n    @@font-face {\n        font-family: 'Font Mail merge icon';\n        font-weight: normal;\n        font-style: normal;\n    }\n\n    [class^=\"sf-icon-\"], [class*=\" sf-icon-\"] {\n        font-family: 'Font Mail merge icon' !important;\n        color: rgba(0, 0, 0, 0.54);\n        font-weight: 600;\n        font-size: 14px;\n    }\n\n    .sf-icon-FinishMerge:before {\n        content: \"\\e700\";\n    }\n\n    .sf-icon-InsertMergeField:before {\n        content: \"\\e701\";\n    }\n</style>\n"
    },
    {
      "target": "src/components/docx-editor-mail-merge/DocxEditorController.cs",
      "content": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Web;\nusing System.Web.Mvc;\n\nnamespace EJ2MVCSampleBrowser.Controllers.DocumentEditor\n{\n    public partial class DocumentEditorController : Controller\n    {\n        public ActionResult MailMerge()\n        {\n            this.DocumentEditorViewResultHelper();\n            List<object> listdata = new List<object>();\n            listdata.Add(new\n            {\n                text = \"ProductName\",\n                id = \"_productname\",\n                Category = \"Drag or click the field to insert.\",\n                htmlAttributes = new { draggable = true }\n            });\n            listdata.Add(new\n            {\n                text = \"ShipName\",\n                id = \"_shipname\",\n                Category = \"Drag or click the field to insert.\",\n                htmlAttributes = new { draggable = true }\n            });\n            listdata.Add(new\n            {\n                text = \"CustomerID\",\n                id = \"_customerid\",\n                Category = \"Drag or click the field to insert.\",\n                htmlAttributes = new { draggable = true }\n            });\n            listdata.Add(new\n            {\n                text = \"Quantity\",\n                id = \"_quantity\",\n                Category = \"Drag or click the field to insert.\",\n                htmlAttributes = new { draggable = true }\n            });\n            listdata.Add(new\n            {\n                text = \"UnitPrice\",\n                id = \"_unitprice\",\n                Category = \"Drag or click the field to insert.\",\n                htmlAttributes = new { draggable = true }\n            });\n            listdata.Add(new\n            {\n                text = \"Discount\",\n                id = \"_discount\",\n                Category = \"Drag or click the field to insert.\",\n                htmlAttributes = new { draggable = true }\n            });\n            listdata.Add(new\n            {\n                text = \"ShipAddress\",\n                id = \"_shipaddress\",\n                Category = \"Drag or click the field to insert.\",\n                htmlAttributes = new { draggable = true }\n            });\n            listdata.Add(new\n            {\n                text = \"ShipCity\",\n                id = \"_shipcity\",\n                Category = \"Drag or click the field to insert.\",\n                htmlAttributes = new { draggable = true }\n            });\n            listdata.Add(new\n            {\n                text = \"ShipCountry\",\n                id = \"_shipcountry\",\n                Category = \"Drag or click the field to insert.\",\n                htmlAttributes = new { draggable = true }\n            });\n            ViewData[\"dataSource\"] = listdata;\n            return View(\"~/Views/Home/docx-editor/mail-merge/DocxEditor.cshtml\");\n        }\n\n    }\n}\n"
    }
  ]
}