Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Ajax.Beginform OnComplete/OnSuccess fired before controller call

Tags:

asp.net-mvc

I'm trying to clear an ajax form after an item has been added to the database however the OnComplete and OnSuccess AjaxOptions get called before the form is submitted. How can I get it so the form is submitted first and the the OnComplete is called.

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

which calls

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

However the DisplayName textbox is cleared before the balue is sent to the controller the form submits to. Is there a way around this.

like image 622
Israfel Avatar asked Dec 08 '09 16:12

Israfel


1 Answers

OnComplete = "ClearForm()" should be called without the parentheses, i.e. OnComplete = "ClearForm". I can't say for sure that it would fix your issue though.

like image 117
Michael Gattuso Avatar answered Sep 23 '22 06:09

Michael Gattuso