admin管理员组文章数量:1418419
I am using tinyMCE (a rich text editor in js). Currently, I have a function as such:
function GetEditorValue() {
var val = tinyMCE.get('valueTextArea').getContent()
}
which returns the text that was entered into the rich text editor. Now, is there a way to pass this data using POST to my mvc controller and access it there? (All this is being done in ASP.NET MVC 2 using C#)
I am using tinyMCE (a rich text editor in js). Currently, I have a function as such:
function GetEditorValue() {
var val = tinyMCE.get('valueTextArea').getContent()
}
which returns the text that was entered into the rich text editor. Now, is there a way to pass this data using POST to my mvc controller and access it there? (All this is being done in ASP.NET MVC 2 using C#)
Share Improve this question asked Feb 4, 2011 at 10:53 snwrsnwr 751 silver badge4 bronze badges1 Answer
Reset to default 3You could send this value using AJAX. For example jQuery provides the .post()
function:
var val = tinyMCE.get('valueTextArea').getContent();
$.post('<%= Url.Action("foo") %>', { value: val }, function(result) {
// TODO: handle the success
alert('the value was successfully sent to the server');
});
and inside your controller action:
[HttpPost]
public ActionResult Foo(string value)
{
// Do something with the value
}
Now obviously because this is a RichText editor the value might contain dangerous characters and ASP.NET will reject them by throwing an exception. To avoid this you could decorate your controller action with the [ValidateInput(false)]
attribute:
[HttpPost]
[ValidateInput(false)]
public ActionResult Foo(string value)
{
// Do something with the value
}
and if you are using ASP.NET 4.0 you should also add the following to your web.config:
<httpRuntime requestValidationMode="2.0" />
本文标签: jqueryPassing value from javascript to mvc controllerStack Overflow
版权声明:本文标题:jquery - Passing value from javascript to mvc controller - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745277041a2651247.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论