[英]In ASP.NET MVC 3, how do I get at the model using Razor Syntax in a Create() View?
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 我在Create()视图中,我想访问模型,以将
<textarea>
into one of the model's properties, the Content property in this case. 放入模型的属性之一(本例中为Content属性)。
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). 我接受HTML标记(粗体,斜体等)时无法使用TextAreaFor。 I'm using TinyMCE on my textarea if that matters.
如果重要的话,我在我的文本区域上使用TinyMCE。
I tried hooking the submit event via JQuery's .submit API: 我试图通过JQuery的.submit API钩住Submit事件:
<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. 但是.submit()出现在$(document).ready中时,处理程序本身从未触发。
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).
我接受HTML标记(粗体,斜体等)时无法使用TextAreaFor。 I'm using TinyMCE on my textarea if that matters.
如果重要的话,我在我的文本区域上使用TinyMCE。
Wrong. 错误。
TextAreaFor()
emits a normal <textarea>
just like your; TextAreaFor()
会像您一样发出普通的<textarea>
。 you can still hook up TinyMCE to it. 您仍然可以将TinyMCE连接到它。
Your actual problem is that <textarea>
s don't fire submit
events. 您的实际问题是
<textarea>
不会触发submit
事件。
You need to handle the <form>
's submit
event. 您需要处理
<form>
的submit
事件。
However, you don't actually need to do that at all. 但是,您实际上根本不需要这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.