代码之家  ›  专栏  ›  技术社区  ›  TonE

使用fckeditor、ajax和asp.net mvc绑定操作参数时出现问题

  •  1
  • TonE  · 技术社区  · 15 年前

    我有一个简单的ASP.NET MVC视图,其中包含一个fckeditor文本框(使用fckeditor的javascript replaceTextArea()函数创建)。这些都包含在ajax.begininform帮助程序中:

    <% 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操作中的测试框字符串始终是“content”,不管fckeditor的内容已更改为什么。如果第二次再次提交Ajax表单(无需进一步更改),则测试框参数将正确包含fckeditor的实际内容。

    如果我使用html.textfarea而不替换为fckeditor,那么它可以正常工作;如果我使用标准的post表单,那么submit代替ajax,那么一切都可以正常工作。

    我做错什么了吗?

    如果没有,是否有合适的/直接的解决方案来解决这个问题?

    1 回复  |  直到 15 年前
        1
  •  1
  •   TonE    15 年前

    该问题与MVC无关,但由结合使用fckeditor和Ajax引起。为了修复上面的代码,我在提交按钮的onclick事件中添加了以下内容:

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

    更多信息 see here .