Products Technologies Demo Docs Blog Support Company

Using TX Text Control MVC in Partial Views

This article shows how to safely use the HTML5-based editor TX Text Control for MVC in partial views in ASP.NET.

Using TX Text Control MVC in Partial Views

Reusable partial views can be used as child views in other views. If you are using the same content again and again, it can be embedded in a partial view. This view can be added in view code or loaded dynamically using JavaScript.

When using the MVC TX Text Control, you will need to remove an existing component from the DOM first as only one TX Text Control is allowed on a view.

The partial view that contains TX Text Control is very simple:

@using TXTextControl.Web
@using TXTextControl.Web.MVC

@Html.TXTextControl().TextControl().Render()

The view that embeds the partial view contains a div into which the partial view is loaded dynamically using jQuery code:

<input type="button" onclick="loadEditor()" value="Load Editor" />

<div id="editor"></div>

<script>
    function loadEditor() {
        // check, if editor exists and
        // closes the WebSocket connection gracefully
        // and removes the whole editor from the DOM.
        if (typeof TXTextControl !== 'undefined')
            TXTextControl.removeFromDom();

        // load the partial view
        $('#editor').load('@Url.Action("EditorPartial")');
    }
</script>

Before the partial view can be loaded, the Javascript: TXTextControl.removeFromDom method is used to close the WebSocket connection gracefully and to remove the editor from the DOM.

The controller method EditorPartial returns the partial view and is called by jQuery asynchronously:

public ActionResult EditorPartial()
{
    // return the partial view with editor
    return PartialView("~/Views/Partials/Editor.cshtml");
}

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Also See

This post references the following in the documentation:

  • Javascript: TXTextControl.removeFromDom Method

ASP.NET

Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.

ASP.NET Core
Angular
Blazor
JavaScript
React
  • Angular
  • Blazor
  • React
  • JavaScript
  • ASP.NET MVC, ASP.NET Core, and WebForms

Learn more Trial token Download trial

Related Posts

ASP.NETMailMergeMVC

Getting Started: ServerTextControl and MailMerge with ASP.NET MVC (.NET…

This article shows how to use the TX Text Control ASP.NET ServerTextControl and MailMerge classes within an ASP.NET web application in Visual Studio 2022.


ASP.NETGetting StartedMVC

Getting Started: Document Viewer with ASP.NET MVC (.NET Framework)

This article shows how to use the TX Text Control ASP.NET document viewer within a .NET Framework web application in Visual Studio 2022.


ASP.NETGetting StartedMVC

Getting Started: Document Editor with ASP.NET MVC (.NET Framework)

This article shows how to use the TX Text Control ASP.NET document editor within a .NET Framework web application in Visual Studio 2022.


ASP.NETJavaScriptDocument Editor

Detect Toggle Button Changes Using a MutationObserver

This article shows how to detect changes of toggle buttons in the ribbon of the web editor using a MutationObserver. The state of a toggle button in the ribbon visualizes the state of a certain…


ASP.NETJavaScriptDocumentViewer

Using the MVC DocumentViewer in ASP.NET Web Forms

The ASP.NET MVC DocumentViewer for ASP.NET provides more features including document signing capabilities than the DocumentViewer for Web Forms. This article shows how to use the MVC…