使用FCKeditor,AJAX和ASP.NET MVC解决问题绑定操作参数

时间:2009-08-18 09:30:10

标签: asp.net-mvc ajax asp.net-ajax

我有一个简单的ASP.Net MVC视图,其中包含一个FCKeditor文本框(使用FCKeditor的Javascript ReplaceTextArea()函数创建)。这些包含在Ajax.BeginForm帮助程序中:

<% using (Ajax.BeginForm("AddText", "Letters", 
         new AjaxOptions() { UpdateTargetId = "addTextResult" }))
{%>
     <div>
        <input type="submit" value="Save" />
     </div>    

    <div>    
    <%=Html.TextArea("testBox", "Content", new { @name = "testBox" })%>

    <script type=""text/javascript"">
    window.onload = function() 
    {
        var oFCKeditor = new FCKeditor('testBox') ;
        var sBasePath = '<%= Url.Content("~/Content/FCKeditor/") %>';
        oFCKeditor.BasePath    = sBasePath;
        oFCKeditor.ToolbarSet = "Basic";
        oFCKeditor.Height = 400;    
        oFCKeditor.ReplaceTextarea() ; 
    }
    </script>

    <div id="addTextResult">

    </div>
<%} %>

控制器的行动是:

[ValidateInput(false)]
public ActionResult AddText(string testBox)
{                   
    return Content(testBox);
}

初次提交Ajax表单时,AddText操作中的testBox字符串始终为“Content”,无论FCKeditor的内容是否已更改为。如果第二次再次提交Ajax表单(没有进一步更改),则testBox参数正确包含FCKeditor的实际内容。

如果我使用Html.TextArea而不用FCKeditor替换它可以正常工作,如果我使用标准的Post表单提交到AJAX,则所有工作都按预期工作。

我做错了吗?

如果没有针对此问题的合适/直接解决方法?

1 个答案:

答案 0 :(得分:1)

这个问题与MVC无关,但是由于FCKeditor与AJAX一起使用引起了这个问题。要修复上面的代码,我将以下内容添加到提交按钮的onclick事件:

<input type="submit" value="Save" onclick="FCKeditorAPI.GetInstance('TestBox').UpdateLinkedField();" />

了解更多信息see here