POST時,TinyMCE不允許MVC控制器接收更新的HTML /文本我不確定我明白目前發生了什麼。我已經查看了一些關於它的信息,這些信息調用了Modal彈出窗口,其中包含一個editHtml
的TextArea
,這個類將觸發我的TinyMCE編輯器啓動。
莫代爾MyView.cshtml:
@model x.Models.Content.Elements.ElementHtml
@Html.Partial("_Tools") //This calls the TinyMCE in the next code window
@using (Ajax.BeginForm("_Edit", "ElementHtmls",
new AjaxOptions
{
HttpMethod = "POST",
OnSuccess = "alert('Updated');",
OnFailure = "alert('Failed');",
UpdateTargetId = "ElementUpdated_" + Model.Oid.ToString()
},
new { id = "ElementForm_" + Model.Oid.ToString() }
))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>ElementHtml</h4>
<p>This: [email protected]()</p>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.Oid)
@Html.HiddenFor(model => model.Name)
<div class="form-group">
@*@Html.LabelFor(model => model.Html, htmlAttributes: new { @class = "control-label col-md-2" })*@
<div class="col-md-12">
//This is the editHtml
//---
@Html.EditorFor(model => model.Html, new
{ htmlAttributes = new { @class = "form-control edithtml" } }
)
//---
@Html.ValidationMessageFor(model => model.Html, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
的JavaScript TinyMCE的:
@Scripts.Render("~/Scripts/tinymce/jquery.tinymce.min.js")
@Scripts.Render("~/Scripts/tinymce/tinymce.min.js")
<script type="text/javascript">
tinymce.init({
selector: 'textarea.edithtml',
branding: false,
height: 250,
menubar: false,
plugins: [
'advlist autolink lists link image charmap print preview anchor',
'searchreplace visualblocks code fullscreen',
'insertdatetime media table contextmenu paste code',
'code'
],
toolbar: 'undo redo | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code',
content_css: "/Content/bootstrap.css"
});
</script>
在模型的保存,我有以下的javascript:
//...
$(dialog).dialog({
title: title,
//...
buttons: {
'Save': function() {
var editForm = $(form);
if (editForm.valid()) {
$.post(editForm.attr('action'), editForm.serialize(), function (data) {
if (data.Error != undefined && data.Error != '') {
console.log("Data error: " + data.Error);
}
else {
$(dialog).dialog('close');
}
});
}
},
'Cancel': function() {
$(this).dialog('close');
}
}
});
//...
在我上面的代碼,我在Modal窗口中有一個Save,這會觸發JQuery的'Save': function() {
,但也注意到我h在我的cshtml上保存按鈕(用於測試),但這不是我想要使用的,但請注意,此保存按鈕在應用edithtml
時工作正常。不確定這些信息是否有用,都提交給同一控制器。
當上述代碼示例中的所有內容都正常工作時,edithtml
不在@Class中,控制器具有ViewModel,但Html
的屬性是我想要更新值的原始值。其他視圖edithtml
(不在Modal中)適用於TinyMCE。
我是否需要在初始化過程中告訴TinyMCE或自定義本節($.post(editForm.attr('action'), editForm.serialize(), function (data) {
)?
任何信息或反饋表示讚賞。