Introduction

We can insert a rich text editor in our project using JQuery and ASP.NET MVC 6. We have many open-source libraries like TinyMCE, CKEditor, and Summernote, allowing us to insert text editors in the ASP.NET MVC project. However, I will be using TinyMCE in this article.

In this article, I will describe the following points.

  1. What is TinyMCE
  2. Creating an ASP.NET MVC 6 Project
  3. Installing TinyMCE
  4. Using TinyMCE in ASP.NET MVC 6 Project
  5. Formating TinyMCE Text Editor

Prerequisites

  1. Visual Studio 2022 is installed on your machine
  2. Basic knowledge of JQuery

What is TinyMCE

TinyMCE is an open-source rich text editor. The output created in this editor is in HTML5 and it can include lists, tables, and other valuable elements. To know more about the TinyMCE please refer here. The below-given image shows a basic UI of the TinyMCE text editor.

text editor UI image

Creating An ASP.NET MVC 6 Project

To create an ASP.NET MVC project you need to do the following steps.

You have successfully created an ASP.NET MVC project. Now you have to install the TinyMCE text editor.

Installing TinyMCE

We can easily install TinyMCE from the official website. To install TinyMCE in our project follow the steps given below.

You have successfully installed TinyMCE SDK and imported it into your project.

Using TinyMCE In ASP.NET MVC Project

Now you have to use this TinyMCE Text Editor in your project using JQuery. To use the text editor first you need to add a Model class and add an HTML form in the Index View of the Home controller. To use TinyMCE Editor follow the below-given steps.

Output

text editor output image

Formatting TinyMCE Text Editor

The Text Editor you have created is very basic. To make it more interactive you can add a lot of plugins, toolbar, menu, and much more to this which are also provided by the TinyMCE. Now we will add more plugins to this as given below.

<script>
    tinymce.init({
    selector: 'textarea#Body',
    width: 600,
    height: 300,
    plugins: [
      'advlist', 'autolink', 'link', 'image', 'lists', 'charmap', 'preview', 
       'anchor', 'pagebreak',
      'searchreplace', 'wordcount', 'visualblocks', 'visualchars', 'code',
      'fullscreen', 'insertdatetime',
      'media', 'table', 'emoticons', 'template', 'help'
    ],
 toolbar: 'undo redo | styles | bold italic | alignleft aligncenter alignright alignjustify | ' +
'bullist numlist outdent indent | link image | print preview media fullscreen | ' +
      'forecolor backcolor emoticons | help',
    menu: {
      favs: { title: 'My Favorites', items: 'code visualaid | 
       ' + 'searchreplace | emoticons' }
    },
    menubar: 'favs file edit view insert format tools table help',
    content_css: 'css/content.css'
           });
</script>

In the above code, you have added a lot of plugins, toolbar, menu, and menubar.

Output

formatted text editor

As we can see in the above image you have added a lot more functionality to this Text Editor.

Article In a Nutshell

  1. First, you need to add an ASP.NET MVC Project in Visual Studio 2022.
  2. You will install TinyMCE SDK from the official website.
  3. Add tinymce folder to the ASP.NET MVC Project.
  4. Add the necessary js file link to the _Layout.cshtml file.
  5. Add the JQuery code to your View to initialize the Text Editor in your View.

Conclusion

In this way, you can add a Rich Text Editor to your ASP.NET MVC Project. We have a lot more Text Editore available but I have used TinyMCE in this article. Text Editors are used mostly for blog websites.

Thank you and Stay Tuned for More

More Articles from my Account