Asp.NET MVC AjaxOptions OnSuccess fires.. too early?

后端 未结 5 1643
情话喂你
情话喂你 2020-12-09 12:27

I\'d like to use the OnSuccess option of AjaxOptions passed as Ajax.BeginForm argument to \"do something\" once the response is completely received and DOM updated. As far a

5条回答
  •  悲哀的现实
    2020-12-09 12:43

    I have been looking in to this problem and it seems that the "On" events are not quite what they seem.

    If you read this post How is OnSuccess measured for a ASP.NET MVC ActionLink? you will see womp saying that the events may fire no matter what happens in the controller. I have also found this in the tests i did by adding all the "On" events to the AjaxOptions Object like this:

    new AjaxOptions()
     {
         UpdateTargetId = "divPlaceholder",
         InsertionMode = InsertionMode.Replace,
         OnSuccess = "alert('OnSuccess')",
         OnBegin = "alert('OnBegin')",
         OnComplete = "alert('OnComplete')",
         OnFailure = "alert('OnFailure')"
    
     }
    

    I have not used the AjaxOptions in any production code I've written but I have had great success with jQuery Ajax calls and the events firing at the correct times.

    A tutorial on ASP.net MVC and jQuery Ajax can be found here and some examples of how to use events can be found in code on this question

    Sorry I've not been able to fix your problem but I hope this alternative will help.

提交回复
热议问题