我正在尝试在 asp mvc 站点上使用 YUI 富文本编辑器 我正在使用此 javascript 代码
var myEditor = new YAHOO.widget.Editor('Body', {
height: '300px',
width: '522px',
dompath: true, //Turns on the bar at the bottom
animate: true //Animates the opening, closing and moving of Editor windows
});
myEditor.render();
``
在此文本区域
<div class="yui-skin-sam">
@Html.TextAreaFor(model => model.Body, new { cols = "50", rows = 10 })
@Html.ValidationMessageFor(model => model.Body)
</div>
编辑器已加载,但当我提交表单时,其内容并未被传递,我不断收到一条验证消息,指出该字段是必需的,如果其中没有任何内容,我应该这样做。
有谁知道我怎样才能让它按照我想要的方式工作?
最佳答案
如果其他人最终遇到此问题,这里是解决方案。
你可以尝试像这样设置handleSubmit:true
var myEditor = new YAHOO.widget.Editor('Body', {
height: '300px',
width: '522px',
dompath: true, //Turns on the bar at the bottom
animate: true, //Animates the opening, closing and moving of Editor windows
handleSubmit: true
}); myEditor.render();
编辑器将尝试附加自身并自动调用我的 myEditor.saveHTML() ,它将内容填充回文本区域。如果像我一样失败,请通过设置如下所示的事件来手动执行此操作。
YAHOO.util.Event.on('somebutton', 'click', function() {
myEditor.saveHTML();
alert("test");
});
其中 somebutton 是表单提交按钮的名称。
当你开始工作时,你将遇到的第二个问题是,当 ASP.NET 在你的模型中找到 html 标签时,它会出错。这是一个不同的问题,所以我不会在这里描述解决方案。
关于c# - 如何让 YUI 编辑器传递其内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10116043/