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

前端 未结 2 850
被撕碎了的回忆
被撕碎了的回忆 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.

    0 讨论(0)
  • 2021-02-04 07:53

    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>
    
    0 讨论(0)
提交回复
热议问题