For my asp.net mvc 5 application I have use TinyMCE text editor. I my application I am passing front end value using formcollection.serialize method. Unfortunately the content of the textarea can't render by formcollection.serialize method. Here is my code below. It will be a great pleasure for me if anyone can help. With Thanks :
tinyMCE.init({ selector: "textarea" }); //========Email Button $("#btnEmail").click(function () { tinyMCE.triggerSave(true, true); $.ajax({ url: '@Url.Action("Email")', type: "POST", data: $('#emailform').serialize(), dataType: "json", traditional: true }); });
<textarea name="emailContent" style="width:100%"></textarea>
After a lot of trying at last I have solved the issue perfectly. There were two things absent from my code: 1. form submission before ajax call and 2. adding an attribute [Validateinput(false)] just above my controller. Here is the final solution below:
// Controller
[ValidateInput(false)]
public ActionResult Email(FormCollection data)
{
foreach (var key in data.AllKeys)
{
var value = data[key];
}
string Content = data["emailContent"];
}
Javascript:
tinyMCE.init({
selector: "textarea"
});
//========Email Button
$("#btnEmail").click(function () {
tinyMCE.triggerSave(true, true);
$('#emailform').submit();
$.ajax({
url: '@Url.Action("Email")',
type: "POST",
data: $("#emailform").serialize(),
dataType: "json",
traditional: true
});
});
//========= HTML
<textarea name="emailContent" style="width:100%"></textarea>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.