Submit Ajax.BeginForm via ActionLink

…衆ロ難τιáo~ 提交于 2020-01-01 17:26:28

问题


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>

回答1:


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.



来源:https://stackoverflow.com/questions/13459954/submit-ajax-beginform-via-actionlink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!