views:

503

answers:

3

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?

A: 

The problem is unrelated to MVC but caused by using FCKeditor in conjunction with AJAX. To fix in the code above I added the following to the submit button's onclick event:

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

For more information see here.

TonE
A: 

thank you verymuch "TonE" it saved my lots of time. this what i want exactly

A: 

In IE after re-use, system crash

peter