更新时间:2023-02-04 18:23:08
(我不知道这是不是***的方式,但它有效)
(I don't know if it is the best way, but it's working)
考虑一个简单模型:
public class Contact
{
public string Notes { get; set; }
}
我正在使用一个简单的jquery脚本来获取wysiwyg并将其置于隐藏的输入中。
I'm using a simple jquery script in order to get the content of the wysiwyg and put it into a hidden input.
当用户点击保存按钮时,我会自动执行此操作。
I do this automatically when the user clicks on the "Save" button.
这是JS:
<script language=javascript>
$(function () {
$('#NotesWysiwyg').wysiwyg();
$('#btnSave').bind('click', function () {
$("#Notes").val($("#NotesWysiwyg").html().replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'));
});
});
HTML内容:
<div id="NotesWysiwyg"style="height:166px; width:395px; border:1px solid lightgray;display:table-cell"></div>
@Html.HiddenFor(contact => contact.Notes)
<button id="btnSave" type="submit">Save</button>
在服务器端:
// Workaround : Encode WYSIWYG HTML
if (model.Notes != null)
model.Notes = WebUtility.HtmlDecode(model.Notes);