加载html文件作为tinymce编辑器中的初始内容

时间:2015-10-08 11:49:38

标签: javascript asp.net-mvc tinymce textarea rich-text-editor

我在我的asp.net mvc项目中设置了tinymce。我想将html文件加载到TinyMCE编辑器内容中,该内容位于另一个目的地。

我跟着tiny Documentation,但是给我的html文件路径有点困惑。

tinyMCE.activeEditor.setContent('<span>some</span> html');

这是我的cshtml文件

@{ }
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>TinyMCE Example</title>
    <!-- TinyMCE Script Reference -->
    <script src="~/scripts/tinymce/tinymce.min.js"></script>
    <!-- Script to wire up your TinyMCE editor -->
    <script type="text/javascript" src="~/Scripts/tinymce/tinymce.min.js"></script>
    <script type="text/javascript">
        tinymce.init({

            selector: "textarea",
            theme: "modern",
            plugins: [
        "advlist autolink lists link image charmap print preview hr anchor pagebreak",
        "searchreplace wordcount visualblocks visualchars code fullscreen",
        "insertdatetime media nonbreaking save table contextmenu directionality",
        "emoticons template paste textcolor colorpicker textpattern imagetools"
    ],
    toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
    toolbar2: "print preview media | forecolor backcolor emoticons",
    image_advtab: true,
    templates: [
        {title: 'Test template 1', content: 'Test 1'},
        {title: 'Test template 2', content: 'Test 2'}
    ],

});
        tinyMCE.activeEditor.setContent(Html);
        </script>
</head>
<body>
    <!-- This will automatically post to your Index method (that is decorated with a HttpPost attribute) -->
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()
        <div>
            <!-- This will contain your HtmlContent and use the TinyMCE editor-->
            @Html.TextAreaFor(model => model.HtmlContent)

            <input type="submit" value="Create" />
        </div>
    }
</body>
</html>

This question也与我的问题有关,但它没有包含如何为html文件提供路径的说明

更新1:

我尝试使用jquery将html加载到TinyMCE textarea中,它在this question中描述

    @section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/jqueryui")


<script type="text/javascript">

    $.get("myhtml.html", function (content) {

        tinyMCE.activeEditor.setContent(content);
    });

</script>
}

但似乎它也无法正常工作

1 个答案:

答案 0 :(得分:0)

您无法直接提供setContent函数的路径。 你需要做的是在后端获取html文件内容并将其发送到你使用setContent方法将其插入编辑器的页面。