After upgrading my ASP MVC from 3 Preview to 3 Beta I see strange behaviour in my Ajax forms.
@using(Ajax.BeginForm("New", new AjaxOptions() {OnSuccess = "onAjaxSuccess", OnFailure = "onAjaxFailure", OnBegin = "onAjaxBegin", HttpMethod = "Post"})) {}
<form action="/Order/New" data-ajax="true" data-ajax-begin="onAjaxBegin" data-ajax-failure="onAjaxFailure" data-ajax-method="Post" data-ajax-success="onAjaxSuccess" method="post"></form>
I have placed an alert
inside my function onAjaxBegin
and it is beeing fired twice, each time i click on my submit button.
Anyone else seen this behaviour? I have not changed anything in the code after upgrading, and it worked perfectly before the upgrade.
one small tip all the time before you using
.live()
, do .die()
:)this will kill all the java scripts attached to this event and will create a new one.
example:
I had the same problem. I had a login partial view in master page that included
jquery.unobtrusive-ajax.min.js
. I also had this file included in my view. So I removed one and the problem is solved now.You can use
bind
instead oflive
in jquery.unobtrusive-ajax.min.js~~~ This is very important.Becauselive
event will call the previous events every time butbind
only calls the current event.Moving
jquery.unobtrusive-ajax.js
outside partial-view solved the issue in my case.I had the same problem, and i found the solution: I included the "
jquery.unobtrusive-ajax.min.js
"-Script
twice :-)this is old but I found something really stupid that is easy to overlook.
Our form also had the following attached to it:
Obviously the .NET code handles this itself.