Created
October 23, 2013 09:09
-
-
Save AlexShkor/7115182 to your computer and use it in GitHub Desktop.
JsonModel in BaseController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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