Search results

Render the RichTextEditorFor control in ASP.NET Core RichTextEditor control

The RichTextEditorFor control can be rendered by passing values from the controller. The formatted Rich Text Editor value is retrieved when submitting the form using the post method.

In the following sample, the RichTextEditorFor control is rendered.

tagHelper
controller.cs
@model EJ2CoreSampleBrowser.Controllers.RichTextEditorModel
<div class="col-lg-12 control-section">
        <div class="control-wrapper">
            <div style='padding-top:40px;'>
                <form method="post">
                    <ejs-richtexteditor ejs-for="Value" id="RTEfor">
                    </ejs-richtexteditor>
                    <div id="errorMessage">
                        <span asp-validation-for="Value"></span>
                    </div>
                    <div id="submitbutton">
                        <ejs-button id="submitButton" content="Submit"></ejs-button>
                    </div>
                </form>
            </div>
        </div>
    </div>
using System.ComponentModel.DataAnnotations;
public class RichTextEditorModel
    {
        [Required(ErrorMessage = "Value is required")]
        // Specify AllowHtml attribute on MVC application alone
        [AllowHtml]
        public string Value { get; set; }
    }
    public partial class HomeController : Controller
    {
        RichTextEditorModel rteModel = new RichTextEditorModel();
        public ActionResult RichTextEditorFor()
        {
            rteModel.Value = "<p>Type or edit the content to post the <b>Rich Text Editor</b> value.</p>";
            return View(rteModel);
        }
        [HttpPost]
        public ActionResult RichTextEditorFor(RichTextEditorModel model)
        {
            rteModel.Value = model.Value;
            return View(rteModel);
        }
    }

The output will be as follows.

RichTextEditorFor