Problem binding action parameters using FCKeditor, AJAX and ASP.NET MVC

Posted by TonE on Stack Overflow See other posts from Stack Overflow or by TonE
Published on 2009-08-18T09:30:10Z Indexed on 2010/04/08 10:23 UTC
Read the original article Hit count: 655

Filed under:
|
|

I have a simple ASP.Net MVC View which contains an FCKeditor text box (created using FCKeditor's Javascript ReplaceTextArea() function). These are included within an Ajax.BeginForm helper:

<% 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>
<%} %>

The controller action hanlding this is:

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

Upon initial submission of the Ajax Form the testBox string in the AddText action is always "Content", whatever the contents of the FCKeditor have been changed to. If the Ajax form is submitted again a second time (without further changes) the testBox paramater correctly contains the actual contents of the FCKeditor.

If I use a Html.TextArea without replacing with FCKeditor it works correctly, and if I use a standard Post form submit inplace of AJAX all works as expected.

Am I doing something wrong?

If not is there a suitable/straight-forward workaround for this problem?

© Stack Overflow or respective owner

Related posts about asp.net-ajax

Related posts about asp.net-mvc