ASP.NET AJAX.BeginForm sends multiple requests

前端 未结 3 1016
广开言路
广开言路 2020-12-15 22:04

Im relatevely new with Asp.net MVC3,

I have a form handled with Ajax, like this:

@using (Ajax.BeginForm(\"dtjson\", new AjaxOptions { HttpMethod = \"Post\"

相关标签:
3条回答
  • 2020-12-15 22:22

    You have added jquery.unobtrusive-ajax.js three times. It had happened to me as well.

    Check in bundle config "~/ui/js/jquery.unobtrusive.*". the * is wildcard to match both minified or un-minified version. As your solution contains both of the files, it is adding "jquery.unobtrusive-ajax.js" and "jquery.unobtrusive-ajax.min.js". Again in your view page or layout page, you have added jquery.unobtrusive-ajax.js/jquery.unobtrusive-ajax.min.js which is making three times request/post

    0 讨论(0)
  • 2020-12-15 22:26

    You have included jquery.unobtrusive-ajax.min.js twice once in the layout once in the partial. So your browser executes the js inside twice which will subscribe twice on the form click event that is why doing two POST instead of one.
    So you need to remove the jquery.unobtrusive-ajax.min.js from the partial.

    Note: If your are using a partial with a layout you don't need to duplicate the js included in the partial because it's already done by the layout. There are some good articles about layouts and partials.

    0 讨论(0)
  • 2020-12-15 22:26

    I my case I had "return View" instead of "return PartialView".

    0 讨论(0)
提交回复
热议问题