I\'ve been playing with the new MVC3 Json Model Binding and it\'s quite nice.
Currently, I can post JSON to controller and bind it. Model Validation occurs nicely too.>
Thanks for this solution. I improved on it a bit by passing a dictionary so that you can use the unobtrusive javascript to put the validation on the individual fields instead of a summary by referencing the key of the dictionary.
private Dictionary GetModelStateErrorsAsString(ModelStateDictionary state)
{
Dictionary errors = new Dictionary();
foreach (var key in ModelState.Keys)
{
var error = ModelState[key].Errors.FirstOrDefault();
if (error != null)
{
errors.Add(key, error.ErrorMessage);
}
}
return errors;
}