# rich-text-editor-paste-from-ms-word

> Rich text editor configured to clean and preserve formatting when pasting content from Word.

**Framework:** aspnet-mvc  **Component:** RichTextEditor  **Variant:** paste-from-ms-word

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/aspnet-mvc/rich-text-editor-paste-from-ms-word.json
```

**Install Package(s)**

```bash
Install-Package Syncfusion.AspNetMvc.RichTextEditor
Install-Package Syncfusion.AspNetMvc.DropDowns
Install-Package Syncfusion.AspNetMvc.Inputs
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/rich-text-editor-paste-from-ms-word/RichTextEditor.cshtml

```cshtml
@using Syncfusion.EJ2
@using EJ2MVCSampleBrowser.Models
@using Syncfusion.EJ2.DropDowns
@section ControlsSection{
    <div class="col-lg-8 control-section">
        <div class="content-wrapper" id="all-option-sample">
            @Html.EJS().RichTextEditor("pasteCleanUp").ContentTemplate(@<text>
                <h4>Paste Cleanup in Rich Text Editor<br></h4><p>The Rich Text Editor automatically <strong>cleans up formatted content</strong> when you paste from external sources like Word, Google Docs, or web pages.</p><p><b>Paste Cleanup properties:</b></p><ul>
                    <li>
                        <strong>Prompt </strong>- specifies whether to enable the prompt when pasting in Rich Text Editor
                    </li>
                    <li>
                        <strong>Plain Text </strong>- specifies whether to paste as plain text or not in Rich Text Editor.
                    </li>
                    <li>
                        <strong>Keep Format</strong>- specifies whether to keep or remove the format when pasting in Rich Text Editor.
                    </li>
                    <li>
                        <strong>Denied Tags</strong> - specifies the tags to restrict when pasting in Rich Text Editor.
                    </li>
                    <li>
                        <strong>Denied Attributes</strong> - specifies the attributes to restrict when pasting in Rich Text Editor.
                    </li>
                    <li>
                        <strong>Allowed Style Properties</strong> - specifies the allowed style properties when pasting in Rich Text Editor.
                    </li>
                </ul><p><span><strong>Try It Out!</strong></span></p><p>Copy content from a web page or document and paste it here. The editor will display a prompt and allow you to input your options.</p>
            </text>).Created("created").PasteCleanupSettings(p => p.Prompt(true)).Render()
        </div>
    </div>

    <div class="col-lg-4 property-section" id="all-option-table">
        <div>
            <table id="property" title="Properties">
                <tbody>
                    <tr>
                        <td>
                            <div>Format Option </div>
                        </td>
                        <td>
                            <div>
                                @Html.EJS().DropDownList("format").PopupHeight("200px").Index(0).DataSource(
                    (IEnumerable<FormatOption>)ViewData["Data"]).Change("formatChange").Fields(new DropDownListFieldSettings { Text = "Format", Value = "Id" }).Render()
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div>Denied Tags </div>
                        </td>
                        <td>
                            <div>
                                @Html.EJS().TextBox("deniedTags").Change("deniedTagsChange").Placeholder("'img[!href]'").Render()
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div>Denied Attributes </div>
                        </td>
                        <td>
                            <div>
                                @Html.EJS().TextBox("deniedAttributes").Change("deniedAttrsChange").Placeholder("'id', 'title'").Render()
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div>Allowed Style Properties </div>
                        </td>
                        <td>
                            <div>
                                @Html.EJS().TextBox("allowedStyleProperties").Change("allowedStyleChange").Placeholder("'href', 'style'").Render()
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
}
<script>
    var rteObj;
    function created() {
        rteObj = this;
    }
    function formatChange() {
        if (format.value === 'Prompt') {
            rteObj.pasteCleanupSettings.prompt = true;
        } else if (format.value === 'Plain Text') {
            rteObj.pasteCleanupSettings.prompt = false;
            rteObj.pasteCleanupSettings.plainText = true;
        } else if (format.value === 'Keep Format') {
            rteObj.pasteCleanupSettings.prompt = false;
            rteObj.pasteCleanupSettings.plainText = false;
            rteObj.pasteCleanupSettings.keepFormat = true;
        } else if (format.value === 'Clean Format') {
            rteObj.pasteCleanupSettings.prompt = false;
            rteObj.pasteCleanupSettings.plainText = false;
            rteObj.pasteCleanupSettings.keepFormat = false;
        }
   }

    function deniedTagsChange(args) {
        onPasteCleanupSettingsChange(deniedTags.value, 'deniedTags');     
    }

    function deniedAttrsChange(args) {
        onPasteCleanupSettingsChange(deniedAttributes.value, 'deniedAttrs');
    }

    function allowedStyleChange(args) {
        onPasteCleanupSettingsChange(allowedStyleProperties.value, 'allowedStyleProps');
    }
    function onPasteCleanupSettingsChange(value, settingsProperty) {
        if (value) {
            var arrayValue = value.split(',').map(function (item) {
                return item.trim().replace(/^['"]|['"]$/g, '');
            });
            rteObj.pasteCleanupSettings[settingsProperty] = arrayValue.filter(function (prop) {
                return prop !== '';
            });
        }
    }
</script>

```

### src/components/rich-text-editor-paste-from-ms-word/RichTextEditorController.cs

```cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Mvc;
using EJ2MVCSampleBrowser.Models;

namespace EJ2MVCSampleBrowser.Models
{
    public class FormatOption
    {
        public string Id;
        public string Format;
        public List<FormatOption> FormatOptions()
        {
            return new List<FormatOption>
            {
                new FormatOption { Id = "1", Format = "Prompt" },
                new FormatOption { Id = "2", Format = "Plain Text" },
                new FormatOption { Id = "3", Format = "Keep Format" },
                new FormatOption { Id = "4", Format = "Clean Format" }
            };
        }
    }
}

namespace EJ2MVCSampleBrowser.Controllers
{
    public partial class RichTextEditorController : Controller
    {
        // GET: /<controller>/
        public ActionResult PasteCleanup()
        {
            ViewData["Data"] = new FormatOption().FormatOptions();
            return View("~/Views/Home/rich-text-editor/paste-from-ms-word/RichTextEditor.cshtml");
        }
    }
}

```
