I'm unable to figure out the correct JSON object I need to pass into jQuery validation's showErrors() method. So on the client I have JavaScript:
var validator = $("form").validate();
validator.showErrors(modelstate_json);
And server-side extracting ModelState errors into JSON is easily done
var errors = (from e in ModelState where e.Value.Errors.Count > 0 select e)
ToDictionary(x =>
x.Key,
x => x.Value.Errors
.Select(y => y.ErrorMessage)
.Concat(x.Value.Errors.Where(y => y.Exception != null)
.Select(y => y.Exception.Message)));
JsonConvert.SerializeObject(errors);
Which gives me something like
'{"Name": "Max 30 characters"}'
But passing this fragment to showErrors() does not trigger validation and display the message.
If I know the correct JSON to feed showErros() then I am hoping I can reverse engineer my serialization routine.
Thanks