In ASP.NET MVC 3, how do I get a model using the Razor syntax in the Create () view?

How can I capture data in my text box and use it in my model?

I am in the Create () view and I want to access the model to put the contents

<textarea> 

into one of the model 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 cannot use TextAreaFor since I accept HTML markup (bold, italics, etc.). I use TinyMCE in my text box, if that matters.

I tried to hook the send event through the jQuery.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 .submit () occurred in $ (document) .ready, the handler itself never fires.

and here is my text box:

 <div class="editor-field"> <textarea id="contentEditor" name="contentEditor"></textarea> </div> 
0
jquery asp.net-mvc
source share
1 answer

I cannot use TextAreaFor since I accept HTML markup (bold, italics, etc.). I use TinyMCE in my text box, if that matters.

Wrong.

TextAreaFor() emits a normal <textarea> , just like yours; you can still connect TinyMCE to it.


Your actual problem is that <textarea> do not fire submit events.
You need to handle the <form> submit event.

However, you don’t really need this at all.

+1
source share

All Articles