I want to do the client side validations but I run into the following problem. If the model is not valid, it returns the view with the error messages in the UpdateTargetId
form, like this:
The part of the form code 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 controller 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);
}
install the nuget microsoft.jquery.unobtrusive.ajax and call your form:
make sure you have the nuget package installed and well referenced and if you can put part of the code of your controller to see if you have no problems in it. Cheers