您可以使用AJAX发送此值。例如jQuery提供.post()
功能:
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');
});
和你的控制器动作中:
[HttpPost]
public ActionResult Foo(string value)
{
// Do something with the value
}
现在很明显,因为这是一个的文本编辑器的值可能包含危险的人物和ASP.NET将拒绝他们抛出异常。为了避免这种情况,你可以用[ValidateInput(false)]
属性装饰你的控制器动作:
[HttpPost]
[ValidateInput(false)]
public ActionResult Foo(string value)
{
// Do something with the value
}
,如果你正在使用ASP.NET 4.0还应该添加下列到你的web.config:
<httpRuntime requestValidationMode="2.0" />
这肯定看起来像答案,即使在我的情况下我的控制器方法没有被调用。不过,我会自己把那部分弄清楚。谢谢一堆。 – snwr 2011-02-04 11:06:22