我想发送textarea
(TinyMCE)的HTML,但输入参数为空。
我错过了什么使它工作?任何线索?
$('#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 :(
答案 0 :(得分:0)
我找到了解决方案
var englishContent = tinyMCE.get('editorEnglishContentCreate').getContent({ format: 'raw' });
console.log(englishContent);
fileData.append('englishContent', englishContent);
C#代码也需要像
一样进行调整[ValidateInput(false)]
[HttpPost]
public JsonResult CreateContent(string englishTitle, string englishContent, string spanishTitle, string spanishContent)
{