2015-10-08 108 views
1

我在我的asp.net mvc項目中設置了tinymce。我想將一個html文件加載到位於另一個目的地的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的說明:

我試圖加載html使用jquery到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> 
} 

但好像它也沒有工作

回答

0

你不能給直接的setContent功能的路徑。 您需要做的是將html文件內容後端獲取並將其發送到您的頁面,並使用setContent方法將其插入到您的編輯器中。

+0

任何示例要跟隨我? – kez

+0

不,完全取決於後端(語言) – Thariama