[英]TinyMCE text area value not render with form collection
For my asp.net mvc 5 application I have use TinyMCE text editor. 对于我的asp.net mvc 5应用程序,我使用了TinyMCE文本编辑器。 I my application I am passing front end value using formcollection.serialize method.
我的应用程序正在使用formcollection.serialize方法传递前端值。 Unfortunately the content of the textarea can't render by formcollection.serialize method.
不幸的是,textarea的内容无法通过formcollection.serialize方法呈现。 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.
我的代码中缺少两件事:1.在ajax调用之前提交表单,以及2.在我的控制器上方添加属性[Validateinput(false)]。 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.