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);
}