Strongly typed HTML helper in EJ 1 ASP.NET MVC RichTextEditor

27 Apr 2018 / 1 minute to read

The RTE control supports strongly typed HTML helpers which use lambda expressions to reference models or view models passed to a view template. These helpers allow you to define the value of the RichTextEditorFor from the model. The following steps explain how to use the strongly typed helpers to create RichTextEditorFor.

Add a class named “RTE” in the Models folder and replace the code with the following code:

  • html
  • public class RTE
    {
        public string value { get; set; }
    }

    In the controller, pass the model to the View.

  • html
  • using UserInterface.Models;
    public ActionResult RichTextEditorFeatures()
    {
        RTE obj = new RTE ();    
        obj.value = "JavaScript is the programming language of HTML and the Web.";
        return View(obj);
    }

    In View, invoke the strongly typed RichTextEditor helper with the lambda expression to set the default value.

  • html
  • @model UserInterface.Models.RTE
    
    @using (Html.BeginForm())
    { 
        @Html.EJ().RTEFor(model => model.value )
    }

    Strongly