Problems with ajax.beginform and client side validation

0

I want to do validations on the client side but I run into the following problem. If the model is not valid, I will return the view with the error messages in UpdateTargetId of the form, so that:

The part of the code of the form would be the following:

@using (Ajax.BeginForm("Index", "Estadistica",
                    new AjaxOptions
                    {
                        OnBegin = "onBegin",
                        OnComplete = "onComplete",
                        OnFailure = "onSuccess",
                        OnSuccess = "onFailure",
                        HttpMethod = "Post",
                        InsertionMode = InsertionMode.Replace,
                        UpdateTargetId = "dvAjaxFormResult"
                    }))
                {...}

The driver code is as follows:

 public ActionResult Index()
    {
        if (!(Session["Usuario"] is Usuario))
        {
            return RedirectToAction("Index", "Login");
        }

        var modelo = new EstadisticaIndex
        {
            FechaDesde = DateTime.Now.Date,
            FechaHasta = DateTime.Now.Date,
            Regional = Funciones.ListaRegional()
        };
        return PartialView(modelo);
    }

    [HttpPost]
    public ActionResult Index(EstadisticaIndex filtroEstadistica)
    {
        if (!(Session["Usuario"] is Usuario))
        {
            return RedirectToAction("Index", "Login");
        }
        var modelo = new EstadisticaIndex
        {
            FechaDesde = DateTime.Now.Date,
            FechaHasta = DateTime.Now.Date,
            Regional = Funciones.ListaRegional()
        };

        if (!ModelState.IsValid)
        {
            return PartialView(modelo);
        }
        return RedirectToAction("EstadisticaConsecutivos", "Estadistica",filtroEstadistica);


    }
    
asked by jeissoni22 17.06.2017 в 18:50
source

1 answer

0

install the microsoft.jquery.unobtrusive.ajax nuget and call your form:

@using (Ajax.BeginForm("Index", "Estadistica", new AjaxOptions() { HttpMethod = "Post", UpdateTargetId = "dvAjaxFormResult", InsertionMode = InsertionMode.Replace }))

Make sure you have the nuget package installed and well referenced and if you can put part of your controller's code to see if you have no problems in it. Greetings

    
answered by 17.06.2017 / 23:08
source