-1

I want to send HTML of textarea (TinyMCE) but the input parameter is empty.

What do I missing to make it working? Any clue?

$('#btnCreateContent').click(function () {

                // Checking whether FormData is available in browser
                if (window.FormData !== undefined) {

                    var fileUpload = $("#FileUpload1").get(0);
                    var files = fileUpload.files;

                    // Create FormData object
                    var fileData = new FormData();

                    // Looping over all files and add it to FormData object
                    for (var i = 0; i < files.length; i++) {
                        fileData.append(files[i].name, files[i]);
                    }

                    // Adding one more key to FormData object
                    fileData.append('englishTitle', $("#inputEnglishTitle").val());
                    fileData.append('englishContent', $("#editorEnglishContentCreate").val());

                    fileData.append('spanishTitle', $("#inputSpanishTitle").val());
                    fileData.append('spanishContent', $("#editorSpanishContentCreate").val());


                    $.ajax({
                        url: '@Url.Action("CreateContent", "Content")',
                        type: "POST",
                        contentType: false, // Not to set any content header
                        processData: false, // Not to process data
                        data: fileData,
                        success: function (data) {

                        },
                        error: function (err) {
                            alert(err.statusText);
                        }
                    });
                } else {
                    alert("FormData is not supported.");
                }
            });
            //

C#

[HttpPost]
public JsonResult CreateContent(string englishTitle, string englishContent, string spanishTitle, string spanishContent)
{

// englishContent is empty :(
4
  • 1
    Use the tinyMce API to get the content or to at least update the element before you try to get it's value
    – charlietfl
    Dec 24, 2016 at 18:26
  • What do you mean by "englishContent is empty"? Does the element #editorEnglishContentCreate have a value that is not an empty string when $.ajax() is called? Dec 24, 2016 at 18:26
  • @charlietfl It seems you are right let me know how to do it please
    – NoWar
    Dec 24, 2016 at 18:48
  • The methods to get content or update the element are in the api docs. I don't know them off the top of my head and would have to look them up myself and no reason you can't do it. The approach does work though ... will be something like var content = editorInstance.getContent() or getData() or similar
    – charlietfl
    Dec 24, 2016 at 18:49

1 Answer 1

0

I found solution

var englishContent = tinyMCE.get('editorEnglishContentCreate').getContent({ format: 'raw' });
console.log(englishContent);
fileData.append('englishContent', englishContent);

Also C# code needs to be adjusted like

[ValidateInput(false)]
[HttpPost]
public JsonResult CreateContent(string englishTitle, string englishContent, string spanishTitle, string spanishContent)
{

Not the answer you're looking for? Browse other questions tagged or ask your own question.