0

Does anyone know how to auto-populate the tinymce editor from the ASP.NET MVC model? In other words, what code do I need to use to set the contents of tinymce?

EDITED:

My problem is that tinyMCE is hiding my textbox contents. It opens blank, even though if I view the source of the page in my browser, it shows the correct info (i.e. from the Model).

Here is my code:

Javascript:

<script type="text/javascript">
    tinyMCE.init({
        theme: "advanced",
        mode: "textareas",
        plugins: "",
        theme_advanced_buttons3_add: "fullpage",
        theme_advanced_toolbar_location: "top"
      }

    );
</script>

Text Area:

<%= Html.TextArea("PostContent", Model.PostContent,30, 68, new {id="newPost"}) %>

Thanks, Jack

5
  • TinyMCE is just fancy javascript ontop of a normal <textarea>, so you shouldn't really need to do anything special. That seems to be the problem? Commented Dec 9, 2009 at 23:01
  • Not quite. I've edited my question to be more clear. Commented Dec 9, 2009 at 23:17
  • Is that a requirement to use TinyMCE? I had all sorts of problems with it and just decided to switch to CKEditor ckeditor.com - it is a lot less headache in my opinion. Maybe you could give it a try. Commented Dec 9, 2009 at 23:25
  • I thought about it. However, I'm trying to be cautious not to violate their license, though. I'm building a closed source, for profit, application for the company that I work for. It appears (reading here: ckeditor.com/license) that they want you to pay a license fee. Is that correct? Thanks again. Commented Dec 9, 2009 at 23:32
  • jchapa: As long as you don't modify CKEditor itself, you'll be fine. You only need to purchase a commercial license if you modify CKEditor itself and you're not willing to contribute your changes back to the original CKEditor source. Commented Dec 9, 2009 at 23:54

1 Answer 1

2
<textarea><%= Model.TextAreaContent %></textarea>

Please note that since you cannot escape the contents of your string (you need proper HTML elements for TinyMCE) you have to be sure that there's nothing nasty within your string. I'm using the HTML Agility Pack to prefilter the contents before putting it into the page.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.