views:

529

answers:

1

I'm getting some very strange behaviour with tinyMCE in an ASP.NET MVC 2 beta app (same happend with MVC 1). I have a view called "edit.aspx" that is called when the user tries to create or edit an entity. The view uses jquery to load tinyMCE where ever it finds textarea's.

Here are my 2 action methods that both call the same "edit.aspx" view

public ActionResult Create()
{
     return View("Edit", new FutureEvent());
}

[HttpGet]
public ActionResult Edit(int id)
{

      FutureEvent futureEvent = (from fe in adminGalleryRepository.FutureEvents
                             where fe.ID == id
                             select fe).FirstOrDefault();

      return View("Edit", futureEvent);

}

The "Edit.aspx" view:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<DomainModel.Entities.FutureEvent>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Future event
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script type="text/javascript">        

        $(function() {
            $("#tabs").tabs();
            $('textarea').tinymce({
                script_url: '../../Scripts/tiny_mce/tiny_mce.js',
                theme: "advanced",
                plugins: "safari,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",

                // Theme options
                theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
                theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
                theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
                theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
                theme_advanced_toolbar_location: "top",
                theme_advanced_toolbar_align: "left",
                theme_advanced_statusbar_location: "bottom",
                theme_advanced_resizing: true
            });
        });

    </script>    


    <h2>Future event</h2>

    <%= Html.ValidationSummary("Edit was unsuccessful. Please correct the errors and try again.") %>

    <% using (Html.BeginForm("Edit", "FutureEvents")) {%>


            <div id="tabs">

                   <ul>
                      <li><a href="#tabs-1">Future event</a></li>
                   </ul>            

                    <div id="tabs-1">

                        <%= Html.Hidden("ID") %>

                         <label class="formLabel"  for="Title">Title:
                            <%= Html.ValidationMessage("Title", "*") %>
                            <%= Html.TextBox("Title", Model.Title, new { size = "40px" })%>
                        </label>

                        <label class="formLabel" for="Info">Info:
                        <br />
                            <%= Html.TextArea("Info", Model.Info, 15, 130, null) %>
                        </label>

                        <br />
                        <label class="formLabel" for="WebSite">Web site address:
                            <%= Html.TextBox("WebSite", Model.WebSite, new { size = "40px" })%>
                        </label>

                    </div>

            </div>

           <div class="clear" ></div>
           <div id="footer" style="text-align: left">     
                <input type="submit" value="Save" />
                <%=Html.ActionLink("Back to List", "List") %>       
           </div>

    <% } %>



</asp:Content>

The strange thing is that the create method renders the "edit" view and the tinyMCE edit appears correctly. But when the edit action method renders the "edit" view, the view appears as you would expect - but without the tinyMCE editor.

No errors appear in FireBug, I get exactly the same behaviour in IE.

Anyone got any idea what's going on.

Regards, Simon

P.S. I also tried removing the $("#tabs").tabs() line but it made no difference.

+1  A: 

It could be related to this line:

script_url: '../../Scripts/tiny_mce/tiny_mce.js',

Since the problem is in the Edit view, maybe the extra parameter adds one level to the folder structure.

Why don't you try:

script_url: '/Scripts/tiny_mce/tiny_mce.js',
Eduardo Molteni
Thanks Eduardo that did the trick.
Simon Lomax