我有一个简单的FCKeditor MVC视图,其中包含一个FCKeditor文本框(使用ASP.Net编辑器的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 form submit而不是AJAX,所有的工作都是预期的。
我做错了什么吗?
如果没有,是否有合适的/直接的解决方案来解决这个问题?
发布于 2009-08-18 10:10:57
这个问题与MVC无关,而是由将FCKeditor与AJAX结合使用而引起的。为了修复上面的代码,我在提交按钮的onclick事件中添加了以下内容:
<input type="submit" value="Save" onclick="FCKeditorAPI.GetInstance('TestBox').UpdateLinkedField();" />有关更多信息,请访问see here。
https://stackoverflow.com/questions/1292848
复制相似问题