HtmlBox(jquery插件)不能在ajax调用中工作

时间:2012-09-06 08:31:28

标签: javascript asp.net-mvc-3 jquery-plugins razor

我正在使用.net framework 4.0和MVC。

我在我的页面中包含HTMLBox(jquery插件),因为我需要一个WYSWYG编辑器来进行文本区域控制。

我有一个名为Instruction的局部视图,我将Textarea控件声明为:

@Html.TextAreaFor(model => model.Instruction, new {@cols = 80, @rows = 10 })

在Ajax调用中,我在页面上填充此部分视图。像这样:

 function EditInstruction(progId) 
    {
            var getUserUrl = '@Url.Action("")';
            var courseType =  $('input:radio[name=CourseType]:checked').val();
            var acadYr = $("#AcadYear").val();
            var sem = $("#Sem").val();

            $.ajax({
                url: '@Url.Action("EditInstruction", "CustomizeInstructionsAndCheckList")',
                data: { progId: progId, acadYr: acadYr, sem: sem, courseType: courseType },
                cache: false,
                type: "get",
                // callback handler that will be called on success
                success: function (response, textStatus, jqXHR) {

               $("#PartailLoadForCheckList").html($(response));  
               callAjaxCallsForCascade(getUserUrl.toString());
               TextEditorForDisplay();


                },
                // callback handler that will be called on error
                error: function (jqXHR, textStatus, errorThrown) {

                },
                // callback handler that will be called on completion
                // which means, either on success or error
                complete: function () {

                }
            });
        }

 This is the code for TextEditorForDisplay(), where I initialize my HtmlBox

 function TextEditorForDisplay() {

        mybox = $("#Instruction").htmlbox({
       toolbars:[
        [
        // Cut, Copy, Paste
        "separator","cut","copy","paste",
        // Undo, Redo
        "separator","undo","redo",
        // Bold, Italic, Underline, Strikethrough, Sup, Sub
        "separator","bold","italic","underline","strike","sup","sub",
        // Left, Right, Center, Justify
        "separator","justify","left","center","right",
        // Ordered List, Unordered List, Indent, Outdent
        "separator","ol","ul","indent","outdent",
        // Hyperlink, Remove Hyperlink, Image
        "separator","link","unlink","image"     
        ],
        [// Show code
        "separator","code",
        // Formats, Font size, Font family, Font color, Font, Background
        "separator","formats","fontsize","fontfamily",
        "separator","fontcolor","highlight",
        ]
        ],
        icons: 'default',
        skin: 'blue',
        success: function () { alert("Successfully posted"); },
        error: function () { alert("Error posting"); }
        });



    }
The problem I face is that, the HtmlBox works only when it is Loaded first and does not work for the subsequent ajax calls. 

这是我得到的错误:TypeError: d.iframe.contentWindow is null

有人可以帮我吗?

由于

1 个答案:

答案 0 :(得分:0)

TinyMCE.MVC

用于TinyMCE HTML文本编辑器的MVC部分编辑器模板

  

<强> PM&GT;安装包TinyMCE.MVC

[UIHint("tinymce_jquery_full"), AllowHtml]
public string Instruction { get; set; }