Html.RenderPartial and Ajax.BeginForm -> Submit is called twice

前端 未结 2 759
无人及你
无人及你 2020-12-28 08:12

I have the following index view:

@model BoringStore.ViewModels.ProductIndexViewModel
@{
    ViewBag.Title = \"Index\";
}

Produkte

<
相关标签:
2条回答
  • 2020-12-28 08:53

    Don't include scripts inside your partial views! They should go the your "main" views or your _layout.cshtml.

    Your problem is that you have included the jquery.unobtrusive-ajax.min.js twice in your page. Once in your Create partial and once somewhere else. Because if you include that script multiple times it will subscribe on the submit event multiple times so you will get multiple submit with a single click.

    So make sure that you have include that script only once in a page. So move the jquery.unobtrusive-ajax.min.js reference into your index view.

    0 讨论(0)
  • 2020-12-28 09:08

    insure that you dont have jquery.unobtrusive-ajax.min.js file duplicated in the layout as mentioned above, and you can check this using browser Inspectors

    Another problem which may cause this error that i have encountered is resting a form using jquery in the ajax request as following

    $("form").trigger("reset"); //just remove this line
    
    0 讨论(0)
提交回复
热议问题