Asp.Net MVC Ajax.BeginForm is not submitting via Ajax

蹲街弑〆低调 提交于 2019-12-02 23:14:25

Do you have the jquery ajax script included? I've noticed this sort of behavior when I didn't include it:

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
Andrew Whitaker

I haven't worked with the ASP.NET MVC AJAX helpers in awhile, but I believe Ajax.BeginForm adds an inline onsubmit handler in the generated (HTML) markup.

If this is the case, calling submit on this form programmatically (your jQuery that triggers the submit event) will not call the onsubmit function of the form, which most likely cancels the normal submit action and submits the form via AJAX.

For more information about why this happens, check out this related answer.

As an alternative, you can post the form via AJAX using

I've found either of these methods less of a hassle than using Microsoft's AJAX helpers.

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