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

前端 未结 2 849
被撕碎了的回忆
被撕碎了的回忆 2021-02-04 07:16

I\'ve got my form as follows

@Using (Ajax.BeginForm(\"Contact\", \"Main\",
2条回答
  •  粉色の甜心
    2021-02-04 07:49

    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

    • The jQuery form plugin.
    • jQuery's built-in AJAX function.

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

提交回复
热议问题