How do I grab the data in my textarea and stuff it in my model?
I'm in a Create() View, and I want to access the model, to put the contents of a
<textarea>
into one of the model's properties, the Content property in this case.
namespace TestTinyMCE.Models {
public class TestBlog {
public int TestBlogId { get; set; }
public string Title { get; set; }
public DateTime PostedOn { get; set; }
public string Tags { get; set; }
public string Content { get; set; }
}
}
I can't use TextAreaFor as I'm accepting HTML markup (bold, italic, and so on). I'm using TinyMCE on my textarea if that matters.
I tried hooking the submit event via JQuery's .submit API:
<script type="text/javascript">
$(document).ready(function () {
tinyMCE.init({
theme: "advanced",
mode: "textareas"
});
$('#contentEditor').submit(function () {
alert('Handler for .submit() called.');
return false;
});
});
</script>
but while the .submit() occurred in $(document).ready, the handler itself never fires off.
and here's my textarea:
<div class="editor-field">
<textarea id="contentEditor" name="contentEditor"></textarea>
</div>
I can't use TextAreaFor as I'm accepting HTML markup (bold, italic, and so on). I'm using TinyMCE on my textarea if that matters.
Wrong.
TextAreaFor()
emits a normal <textarea>
just like your; you can still hook up TinyMCE to it.
Your actual problem is that <textarea>
s don't fire submit
events.
You need to handle the <form>
's submit
event.
However, you don't actually need to do that at all.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.