【问题标题】:Tinymce not loading in partial view MVC3Tinymce 未在部分视图 MVC3 中加载
【发布时间】:2014-01-24 14:17:37
【问题描述】:
$("#ddl").change(function () {
        var strSelected = "";
        $("#ddl option:selected").each(function () {
            strSelected += $(this)[0].value;
        });
        if (strSelected.length != 0) {
            var url = "/Reseller/MailPartial/?resellerId=" + strSelected;
            $("#mail").empty();
            $("#mail").load(url);
        }

这是我用来在我的视图中加载部分的代码(部分只有 1 个标签和 1 个编辑器,应该加载 tinymce)。我的模型中有 [UIHint("tinymce_jquery_full"), AllowHtml] ,并且 tinymce 编辑器在其他视图中加载完全正常。但是当我使用部分视图时,它会以纯文本区域的形式返回。如何解决这个问题?

谢谢

编辑:

我想通了,ijaz 几乎是正确的;)

我需要像 ijaz 所说的那样重新初始化 tinymce,但即使我像 ijaz 所说的那样调用 INitTinyMCE 也没关系,因为元素尚未加载到 html,我不知道为什么。解决方案是在元素加载到页面后调用 initTinyMce。

我尝试使用 $("#mail").load(url, InitTinyMCE()); 但它没有用。

元素加载后如何调用 InitTinyMCE() 有什么想法吗?它现在正在工作,但它依赖于按下另一个按钮来触发 InitTinyMCE()

再次编辑 我将代码更改为纯 ajax,不再使用 .load()

很抱歉这么乱:)

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-3 tinymce partial-views


    【解决方案1】:

    在上面的代码中,[UIHint] 似乎没有正确应用。所以让事情开始吧,请手动初始化 TinyMCE,我的意思是把你的代码改成,

     $("#ddl").change(function () {
                var strSelected = "";
                $("#ddl option:selected").each(function () {
                    strSelected += $(this)[0].value;
                });
                if (strSelected.length != 0) {
                    var url = "/Reseller/MailPartial/?resellerId=" + strSelected;
                    $("#mail").empty();
                    $("#mail").load(url);
    **Re-Init TinyMCE** 
    InitTinyMCE();
                    }
    
    function InitTinyMCE()
    {
    
      $('#@ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty)').tinymce({
    
                // Location of TinyMCE script
                script_url: '@Url.Content("~/Scripts/tinymce/tiny_mce.js")',
                theme: "advanced",
    
                height: "170",
                width: "240",
    
                verify_html : false,
                plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",
    
                // Theme options
                theme_advanced_buttons1: "undo, redo,pasteword,|, bold, italic, underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,image, emotions" ,
                theme_advanced_buttons2: "charmap, bullist, numlist,|,formatselect,fontselect,fontsizeselectcode, |,tiny_mce_wiris_formulaEditor,  fullscreen",
                theme_advanced_buttons3: "",
                theme_advanced_toolbar_location: "top",
                theme_advanced_toolbar_align : "left",
                theme_advanced_statusbar_location : "bottom",
                theme_advanced_resizing : true,
    
                // Example content CSS (should be your site CSS)
                content_css : "@Url.Content("~/Scripts/tinymce/css/content.css")",
                convert_urls : false,
    
                // Drop lists for link/image/media/template dialogs
                template_external_list_url : "lists/template_list.js",
                external_link_list_url : "lists/link_list.js",
                external_image_list_url : "lists/image_list.js",
                media_external_list_url : "lists/media_list.js"
    
            });
    }
    

    【讨论】:

    • 我该怎么做?我也不是第一次初始化它。据我所知,UIHint 已被应用,当我在 tinymce 编辑器文件中放置断点时,它会被命中。如果你能解释如何重新初始化tinymce,请做,谢谢
    • 实际上 UIHent 与 DataEditor 或 DataDisplay 模板一起工作,如果它在其他页面中工作,那么您的项目在您的 Views 或 Views/Shared 文件夹中有这些模板。请检查它可能对您有帮助的代码。
    • 我做了,但我找不到任何有用的东西。这是代码pastebin.com/1k7AYU3j
    • 您的浏览器中是否出现任何类型的 java 脚本错误?并尝试将 $('#@ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty)') 替换为实际的 Id (您的浏览器显示的)您的部分视图具有的文本区域。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多