0
votes

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

1
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?Jørn Schou-Rode
Not quite. I've edited my question to be more clear.jchapa
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.Tamas Czinege
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.jchapa
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.Tamas Czinege

1 Answers

2
votes
<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.