通过ActionLink的提交Ajax.BeginForm [英] Submit Ajax.BeginForm via ActionLink
问题描述
我试图用提交,而不是一个提交按钮的超链接的Ajax.BeginForm。我的提交按钮测试和动作识别由测试Request.IsAjaxRequest基于出任阿贾克斯,但如果我尝试以下IsAjaxRequest返回false:
< A HREF =JavaScript的:无效(0)的onclick =JavaScript的:document.forms [0] .submit();返回false;>更新< / A>
的形式挂到微软的Ajax库,所以你不能只是调用form.submit(),因为有线了AJAX事件没有被激活。您有几种选择:
- 使用一个提交,而不是一个链接按钮
- 删除该MS Ajax的东西,并手动关联起来与jQuery的AJAX的职位(这是什么我会做)
- 调用MS阿贾克斯提交功能
有关第三个选项,而不是
的onclick =JavaScript的:document.forms [0] .submit();返回false;
尝试
的onclick =JavaScript的:$('#形式')的onsubmit();返回false;
不过,我从来没有用过它,所以我不知道它是否会奏效。你也可以看看<一个href=\"http://paululvinius.word$p$pss.com/2009/03/03/how-you-dynamically-submit-a-aspnet-mvc-ajax-form-from-javascript-and-jquery/\"相对=nofollow>这里的解决方案,因为它听起来就像你正在试图完成什么。
I am trying to submit an Ajax.BeginForm using an hyperlink as opposed to a Submit Button. I tested with the submit button and the action recognizes the post as Ajax based by test Request.IsAjaxRequest, however if I try the following IsAjaxRequest returns false:
<a href="javascript:void(0)" onclick="javascript:document.forms[0].submit(); return false;">Update</a>
The form is hooked into Microsoft's Ajax library, so you can't just call form.submit() because the wired up ajax events aren't activated. You have a few options:
- Use a submit button instead of a link
- Drop the MS Ajax stuff and manually wire up your ajax posts with jQuery (this would be what I would have done)
- Call the MS Ajax submit function
For the third option, instead of
onclick="javascript:document.forms[0].submit(); return false;"
Try
onclick="javascript:$('#form').onSubmit(); return false;"
But I've never used it so I don't know if it will work. You might also take a look here for the solution, as it sounds exactly like what you are trying to accomplish.
这篇关于通过ActionLink的提交Ajax.BeginForm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!