I'm developing a web app with asp.net mvc 3 and I have some form that POST to an async action (via ajax). This action recives a ViewModel with some data annotations to validate it. The validation works fine but when the validators return a error I don't know how can I return it to show in my view (because the POST was made by ajax).
My action is something like:
[HttpPost]
public ActionResult SaveCustomer(CustomerViewModel input) {
if (!ModelState.IsValid) { // <-- business validation
return Json(new { success = false, errors = ???});
}
// persist
return Json(new { success = true });
}
How can I show this errors with jquery validate in my view? If it's possible to post some code to sample... I would appretiate that!
Thanks guys!