Reputation: 21621
In a previous question someone point out to me that TinyMCE is a nice and free WYSIWYG editor. Since then, the easiest part has been downloading the resource and have a editor being displayed on an ASP.NET MVC sample page. However, I haven't yet been able to make it work (even after surfing in the net - even in the TinyMCE's website I didn't see anything for first time user).
Well, maybe the main point is to know how the thing's supposed to work. For instance, I've placed a button in the same Html.BeginForm where the TextArea is located. But when I clicked it, there was no post-back happening. So, here's my question:
What the concept behind the editor?
If someone can provide me with resource on that, that would nice. However, for now, I'd like to know how that's work.
Thanks for helping.
Upvotes: 4
Views: 4165
Reputation: 13050
TinyMCE takes a standard <textarea>
element and turns it into a Rich Text Editor using JavaScript. So in your ASP.NET MVC Views you simply create a textarea in the normal way eg
<% Html.TextAreaFor(m => m.Description) %>
When TinyMCE converts this to a textarea it'll still maintain the same id's and name attributes on your textarea element:
<textarea id="Description" name="Description"></textarea>
So model binding should continue to work as normal, it's the name attribute in that code sample above that gets submitted when you post, TinyMCE won't change that, so your POST data will look something like: Description=<p>Hello world</p>&MyButton=Submit
(form POST data is simply name/value pairs separated by &sersands).
So in your Controller Action:
[HttpPost]
public ActionResult SaveProduct(Product product)
{
string description = product.Description;
// Save Product to database (snip)
}
'description' variable will contain the raw HTML markup from TinyMCE. So this should all work as normal, not sure why it isn't. Can you verify that the form is set up and posting as normal, eg. by removing the TinyMCE and just having a standard textarea.
Also, you're not using the <asp:TinyMCE
WebForms control by any chance?
Upvotes: 5
Reputation: 24754
TinyMCE overlays on top of a textarea.
Use a TinyMCE textarea just like you'd use a regular textarea.
Upvotes: 1