Skip to content

Instantly share code, notes, and snippets.

@AlexShkor
Created October 23, 2013 09:09
Show Gist options
  • Save AlexShkor/7115182 to your computer and use it in GitHub Desktop.
Save AlexShkor/7115182 to your computer and use it in GitHub Desktop.
JsonModel in BaseController
protected JsonResult JsonModel<T>(T model) where T : BaseViewModel
{
model.Errors = GetErorsModel().ToList();
return Json(model);
}
protected IEnumerable<ValidationError> GetErorsModel()
{
foreach (var state in ModelState)
{
foreach (var error in state.Value.Errors)
{
yield return new ValidationError(error.ErrorMessage, state.Key);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment