user1754692
user1754692

Reputation: 21

Getting and setting the html from TinyMCE in MVC project

I'm working on an MVC project using TinyMCE. I have a model that contains a string property that is the HTMLContent. I would like the Get action method to pull the HTML from a file and set the text for TinyMCE. The post method should pull the new TinyMCE html and save it to the file.

Currently, the get works when using Html.TextArea and then using HttpUtility.Decode to decode the model.HTMLContent property in the .aspx page.

<%= Html.TextArea("elm1", HttpUtility.HtmlDecode(Model.HTMLContent), new {@name="elm1", @class="tinymce" }) %>

However, on post, the model.HTMLContent property is null. If I use Html.TextAreaFor, then the post model contains the html, BUT the GET does not decode the string TinyMCE's text area is initially set to. I try to decode or encode on the server side but this doesn't work.

I've done a lot of research and cannot find any examples of both setting and getting the TinyMCE HTML with MVC, just the getting. Any help would be greatly appreciated.

Upvotes: 1

Views: 741

Answers (1)

Garvin
Garvin

Reputation: 487

You should inspect your request object when having issues such as this. You are attempting to bind to a model property called HTMLContent but your field has a name called elm1. The name of the field should match the name of the property in your model if you want automatic model binding to work.

Upvotes: 1

Related Questions