[英]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.