[英]Cannot read property 'getContent' of undefined in Tinymce
我正在尝试使用Tinymce编辑器中的富文本格式发送邮件并显示,但是在javascript中调试时出现以下错误: 无法读取未定义的属性“ getContent”
这是我的代码//模型
public class EmailModel
{
public int Id { get; set; }
public string Sender { get; set; }
public string Receiver { get; set; }
public string SubjectText { get; set; }
[AllowHtml]
[UIHint("tinymce_full_compressed")]
[Display(Name = "BodyText")]
public string BodyText { get; set; }
public string AboutMe { get; set; }
}
public class EmailListModel
{
public List<EmailModel> ListEmailModel { get; set; }
public EmailModel EmailModel { get; set; }
}
//视图
@model StarRatingControl.Models.EmailListModel
@{
Layout = "~/Views/Shared/_Layout.cshtml";
ViewBag.Title = "EmployeeMail";
}
<h2>EmployeeMail</h2>
<div class="form-horizontal">
<h4>About</h4>
<hr />
@Html.ValidationSummary(true)
<div class="form-group">
@Html.LabelFor(model => model.EmailModel.SubjectText, new { @class = "col-md-12" })
<div class="col-md-12">
@Html.EditorFor(model => model.EmailModel.SubjectText, new { @style = "width:790px;" })
@Html.ValidationMessageFor(model => model.EmailModel.SubjectText)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.EmailModel.BodyText, new { @class = "col-md-12" })
<div class="col-md-12">
@Html.EditorFor(model => model.EmailModel.BodyText)
@Html.ValidationMessageFor(model => model.EmailModel.BodyText)
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" id="sendMail" value="Create" class="btn btn-default" />
</div>
</div>
</div>
// JS
$("#sendMail").click(function () {
$('#' + 'BodyText').html(tinymce.get('BodyText').getContent());
var subject = $("#SubjectText").val();
var body = $("#BodyText").val();
var data = {
subject: subject,
body: body
};
alert(body);
$.post('@Url.Action("SendEmpMail", "ManageEmployee")', data, function (res) {
if (res)
{
alert('Mail Sent Successfully');
}
});
});
重要的一点是,当我在视图中使用EmailModel时,一切工作正常,但由于显示,我使用了EmailListModel。 使用此模型后,我无法获得价值。
tinymce.get()
命令要求您传递TinyMCE替换的<textarea>
的ID。 如果您看到...
Cannot read property 'getContent' of undefined
...那么您的tinymce.get()
命令不正确。 所以问题变成了这段代码是什么:
@Html.EditorFor(model => model.EmailModel.BodyText)
在浏览器中创建? 基础<textarea>
的ID是什么? 一旦知道了,您就可以使用get()
命令来定位该编辑器实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.