MVC Ajax.Beginform OnComplete / OnSuccess launched before calling the controller

I am trying to clear an ajax form after an element has been added to the database, however OnComplete and OnSuccess AjaxOptions are called before submitting the form. How can I get it so that the form is submitted first and is called OnComplete.

<% using (Ajax.BeginForm("AddTable", new AjaxOptions { UpdateTargetId = "tables", InsertionMode = InsertionMode.InsertAfter, OnComplete = "ClearForm()" })) {%> 

which causes

 function ClearForm() { $('#DisplayName').val(''); } 

However, the DisplayName text field is cleared before the ballet is passed to the controller to which the form is submitted. Is there any way around this.

+7
asp.net-mvc
source share
1 answer

OnComplete = "ClearForm()" should be called without parentheses, i.e. OnComplete = "ClearForm" . I can’t say for sure that this will fix your problem.

+13
source share

All Articles