2011-06-17 61 views
0

我嘗試創建模板,這個模板應該來自1個元素 - textarea,但是這個textarea應該擴展到TinyMCE控件。 我嘗試通過以下ascx控件做到這一點:ASP.NET MVC模板問題

<textarea id="SubComment" name="SubComment" style="width: 80%"> 
<% = Html.Encode(ViewData.TemplateInfo.FormattedModelValue) %></textarea> 
    <script type="text/javascript" src="/Scripts/jquery-1.3.2.min.js"></script> 
    <script type="text/javascript"> 
     tinyMCE.init({ 
      // General options 
      mode: "textareas", 
      theme: "advanced", 
      plugins: "spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,nonbreaking,xhtmlxtras,template,imagemanager,videoupload", 

      // Theme options 
      theme_advanced_buttons1: <% = txtAdvButtons %>, 
      theme_advanced_buttons2: "tablecontrols", 
      theme_advanced_buttons3: "", 
      theme_advanced_toolbar_location: "top", 
      theme_advanced_toolbar_align: "left", 
      theme_advanced_statusbar_location: "", 
      theme_advanced_resizing: true, 
      onchange_callback: "changed", 

      // Example content CSS (should be your site CSS) 
      content_css: "css/example.css", 

      // Drop lists for link/image/media/template dialogs 
      template_external_list_url: "js/template_list.js", 
      external_link_list_url: "js/link_list.js", 
      external_image_list_url: "js/image_list.js", 
      media_external_list_url: "js/media_list.js", 

      // Replace values for the template plugin 
      template_replace_values: { 
       username: "Some User", 
       staffid: "991234" 
      }, 

      setup: function(editor) { 
       editor.addButton('myupload', { 
        title: 'Insert image', 
        image: '/tiny_mce/plugins/imagemanager/pages/im/img/insertimage.gif', 
        onclick: function() { 
         mcImageManager.upload({ 
          path: '{0}', 
          onupload: function(info) { 
           var i, html = ''; 

           for (i = 0; i < info.files.length; i++) 
            html += '<img src="' + info.files[i].url + '" />'; 

           editor.execCommand('mceInsertContent', false, html); 
          } 
         }); 
        } 
       }); 
      } 

     }); 
</script> 

,但是當我嘗試使用這個模板我看到簡單的文本區域。如何應用這個JavaScript擴展(它可以正確地使用ascx控件)? 謝謝

+0

你是否包括與每個模板的jQuery腳本?您應該將該腳本標記放在Head中。 –

+0

當它放在視圖頭 - 它不通過模板工作,我試圖找到其他方式 –

回答

1

因此,我閱讀了tinyMCE的文檔,結果發現您在那裏發佈的代碼應該放在Head標籤或其他腳本文件中。

您的textarea改成這樣:

<textarea name="SubComment" class="tinyMCETextArea" style="width: 80%"> 

而在你的tinyMCE的初始化代碼:

$(function(){ 
    tinyMCE.init({ 
     /// all your options 
     editor_selector: "tinyMCETextArea", 
     /// More stuff 
    }); 
}); 
+0

它如何可以幫助我?如果沒有模板,textarea可以直接查看,該編輯器將正確顯示。如果通過模板 - 則顯示爲簡單文本區 –

+0

嘗試將tinyMCE包裝在文檔中。我更新了我的例子。 –

+0

它不能幫助我的模板:(不起作用 –