Edit this page

Editor HtmlHelper Overview

The Editor HtmlHelper extension is a server-side wrapper for the Kendo UI Editor widget.

Getting Started

Configuration

Below are listed the steps for you to follow when configuring the Kendo UI Editor.

  1. Make sure you followed all the steps from the introductory article on Telerik UI for ASP.NET MVC.

  2. Create a new action method which renders the view.

    Example
        public ActionResult Index()
        {
            return View();
        }
    
  3. Add an Editor.

    Example
    
            <%: Html.Kendo().Editor()
                    .Name("editor") //The name of the Editor is mandatory. It specifies the "id" attribute of the widget.
                    .Value("<p>Initial value</p>") //Set the value of the Editor.
            %>
    
    
            @(Html.Kendo().Editor()
                  .Name("editor") //The name of the Editor is mandatory. It specifies the "id" attribute of the widget.
                  .Value("<p>Initial value</p>") //Set the value of the Editor.
            )
    

Server Value Processing

The Editor value is posted as a string and mapped to a variable with the name of the widget. Note that the posted value is HTML-encoded by default, to circumvent the ASP.NET request validation. To decode the value, use the HttpUtility.HtmlDecode method.

Example
    [HttpPost]
    public ActionResult Save(string editor)
    {
        string value = HttpUtility.HtmlDecode(editor);

        return View();
    }

Important

You can suppress the Editor encoding by specifying Encode(false) via the fluent API and adding the AllowHtml attribute to the model field that stores the HTML.

Event Handling

You can subscribe to all Editor events.

By Handler Name

The following example demonstrates how to subscribe to events by a handler name.

Example

        <%: Html.Kendo().Editor()
                .Name("editor")
                .Events(e => e
                    .Change("editor_change")
                )
        %>
        <script>
            function editor_change() {
                //Handle the change event.
            }
        </script>

        @(Html.Kendo().Editor()
              .Name("editor")
              .Events(e => e
                    .Change("editor_change")
              )
        )
        <script>
            function editor_change() {
                //Handle the change event.
            }
        </script>

By Template Delegate

The following example demonstrates how to subscribe to events by a template delegate.

Example

        @(Html.Kendo().Editor()
              .Name("editor")
              .Events(e => e
                  .Change(@<text>
                    function() {
                        //Handle the change event inline.
                    }
                    </text>)
              )
        )

Reference

Existing Instances

To reference an existing Kendo UI Editor instance, use the jQuery.data() configuration option. Once a reference is established, use the Editor API to control its behavior.

Example
    //Put this after your Kendo UI Editor for ASP.NET MVC declaration.
    <script>
    $(function() {
        //Notice that the Name() of the Editor is used to get its client-side instance.
        var editor = $("#editor").data("kendoEditor");
    });
    </script>

See Also

For runnable examples on the Kendo UI Editor in ASP.NET MVC applications, browse its How To documentation folder.