ASP.NET MVC模板问题

时间:2011-06-17 21:49:24

标签: javascript asp.net-mvc-2 templates

我尝试创建模板,这个模板应该来自1个元素 - textarea,但是这个textarea应该扩展到TinyMCE控件。 我尝试通过以下ascx控件来实现:

<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>

但是当我尝试使用这个模板时,我看到简单的textarea。如何应用这个javascript扩展(它可以正常的ascx控件)? 感谢

1 个答案:

答案 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
    });
});