I have a registration form that works, that when executed successfully calls Limpiar
that makes the form blank, but if I put the the OnBegin
form stops working completely
@using (Ajax.BeginForm("Registrar", "", new AjaxOptions
{
HttpMethod = "POST",
//OnBegin = "Iniciar",
OnSuccess = "Limpiar",
UpdateTargetId = "div_tabla_sucursal",
InsertionMode = InsertionMode.Replace
}
In a script I have the following:
function Iniciar () {
// Deshabilitamos el botón de Submit
$("#btn_registrar").prop("disabled", true);
};
var Limpiar = function () {
// Limpia el formulario
$("#Frm_Registro").trigger("reset");
// Habilitamos el botón de Submit
$("#btn_registrar").prop("disabled", false);
// Mostramos un mensaje de éxito.
$("#ExitoAlert").show("slow").delay(2000).hide("slow");
};
the first time it was executed correctly and if it did not make any modifications it stopped executing, when I remove it onBegin
from the form onSuccess
it executes without problems, but when I place it it stops working completely.
Two things:
First : You are not indicating in
Ajax.BeginForm
the Controller to which the submit of the form should be directedSecond : You are misdefining the function
Iniciar()
that is called in theOnBegin
AJAX call.Define it the same way you defined the
Limpiar
del functionOnSuccess
, and it should work for you.The code would be the following:
PS: I recommend you read this article AJAX Web Forms in ASP.NET MVC 5 - Ajax Helpers , where you can see how to develop AJAX Web Forms in ASP.NET MVC with the Ajax Helper
@Ajax.BeginForm()
.