c# - 如何让 YUI 编辑器传递其内容

标签 c# javascript asp.net asp.net-mvc yui

我正在尝试在 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/

相关文章:

c# - MVVM 中的数据库模型

javascript - HTML 节点图生成器?

javascript - 这个 javascript/Jquery 代码的执行顺序是什么?

c# - 如何在 div 向下滚动而不是浏览器窗口向下滚动时加载中继器?

c# - 我试图在绑定(bind)到文本框的 ASPX 页面中隐藏文本

c# - 在 ListView 中加载并显示所有项目后会触发哪个事件?

c# - 从 foreach 中的 Dictionary 中删除一个键会导致问题吗?或者我应该更好地构建一个新的词典?

c# - 如何在不检查 null 或 0 的情况下为 sqlparameter NULL 值赋值?

javascript - jquery验证如何仅从指定的隐藏字段隐藏错误消息

.net - IIS/.NET 上的 Blackberry Push Service Initiator