In this article I will explain with an example, how to upload, add and display Image in TinyMCE Rich Text Editor TextBox using jQuery in ASP.Net MVC Razor.
The File will be uploaded with Progress Bar using HTML5 FormData, JSON and jQuery AJAX.
You will need to import the following namespace.
using System.IO;
The Controller consists of following Action methods.
Action method for handling GET operation
Inside this Action method, simply the View is returned.
Action method for handling POST operation
Inside this Action method, the submitted value of the TinyMCE RichTextBox is captured and then set into a ViewBag variable.
Action method for handling POST operation for File uploads
Inside this Action method, the uploaded File is read and saved to a Folder (Directory) on Server’s Disk.
Finally, the saved file path is returned back to the client using Content function.
public class HomeController : Controller
    // GET: Home
    public ActionResult Index()
        return View();
    public ActionResult Index(string richText)
        ViewBag.RichText = richText;
        return View();
    public ActionResult UploadFile()
        //Fetch the Uploaded File.
        HttpPostedFileBase postedFile = Request.Files[0];
        //Set the Folder Path.
        string folderPath = Server.MapPath("~/Uploads/");
        //Set the File Name.
        string fileName = Path.GetFileName(postedFile.FileName);
        //Save the File in Folder.
        postedFile.SaveAs(folderPath + fileName);
        return Content("/Uploads/" + fileName);
The View consists of an HTML Form which has been created using the Html.BeginForm method with the following parameters.
ActionName – Name of the Action. In this case the name is Index.
ControllerName – Name of the Controller. In this case the name is Home.
FormMethod – It specifies the Form Method i.e. GET or POST. In this case it will be set to POST.
The Form consists of an HTML FileUpload element, a Progress element, a TextArea, a Submit Button and a SPAN element.
The TinyMCE plugin has been applied to the TextArea by rendering the TinyMCE from its CDN
Inside the jQuery document ready event handler, the FileUpload has been assigned jQuery Change event
Inside Change event handler, the File is read from the HTML FileUpload element and is added to the HTML5 FormData object.
Then, an AJAX call is made to the Action method using jQuery and the File is uploaded using XmlHttpRequest (XHR).
Next, a Progress event handler is attached to the XmlHttpRequest (XHR), which displays the progress of the File being uploaded using the HTML5 Progress element.
Finally, the uploaded Image File is displayed in TinyMCE Rich Text Editor using the execCommand.
Submitting Form
When the submit button is clicked, the value of theRich Text Editor TextBox is displayed using the ViewBag variable.
    Layout = null;
<!DOCTYPE html>
    <meta name="viewport" content="width=device-width" />
    @using (Html.BeginForm("Index", "Home", FormMethod.Post))
        <input type="file" id="fuUpload" /><br />
        <progress id="fileProgress" style="display: none"></progress><br />
        @Html.TextArea("RichText")<br />
        <input type="submit" value="Submit" />
    <script type="text/javascript" src=""></script>
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
        tinymce.init({ selector: 'textarea', width: 300 });
        $(function () {
            $("#fuUpload").change(function () {
                var formData = new FormData();
                formData.append("file", $("#fuUpload")[0].files[0]);
                    url: '/Home/UploadFile',
                    type: 'POST',
                    data: formData,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (file) {
                        var img = "<img style = 'height:80px;width:80px' src = '" + file + "' />";
                        tinyMCE.activeEditor.execCommand("mceInsertContent", true, img);
                    error: function (a) {
                    failure: function (a) {
                    xhr: function () {
                        var fileXhr = $.ajaxSettings.xhr();
                        if (fileXhr.upload) {
                            fileXhr.upload.addEventListener("progress", function (e) {
                                if (e.lengthComputable) {
                                        value: e.loaded,
                            }, false);
                        return fileXhr;
Setting the maxRequestLength and maxAllowedContentLength settings in the Web.Config file
In the Web.Config file, the maxRequestLength and maxAllowedContentLength settings are set as shown below.
The maxRequestLength setting accepts value in KB and it is set to 1048576 KB i.e. 1 GB and the maxAllowedContentLength setting accepts value in Bytes and it is set to 1073741824 Bytes i.e. 1 GB.
<?xml version="1.0"?>
        <!-- 1GB in kilobytes, default is 4096 KB or 4MB-->
        <httpRuntime maxRequestLength="1048576" />
                <!-- 1GB in Bytes, default is 30000000 or approx. 28.6102 MB-->
                <requestLimits maxAllowedContentLength="1073741824" />
ASP.Net MVC: Upload, Add and Display Image in TinyMCE Rich Text Editor using jQuery