Created
January 2, 2014 23:46
-
-
Save thefringeninja/8229585 to your computer and use it in GitHub Desktop.
Validation Errors
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
public class ValidationErrorsViewModel : IEnumerable<ValidationErrorViewModel> | |
{ | |
private readonly IEnumerable<ValidationErrorViewModel> errors; | |
public ValidationErrorsViewModel(ModelValidationResult model) | |
{ | |
errors = from error in model.Errors | |
from member in error.MemberNames | |
select new ValidationErrorViewModel(member, error.GetMessage); | |
} | |
#region IEnumerable<ValidationErrorViewModel> Members | |
public IEnumerator<ValidationErrorViewModel> GetEnumerator() | |
{ | |
return errors.GetEnumerator(); | |
} | |
IEnumerator IEnumerable.GetEnumerator() | |
{ | |
return GetEnumerator(); | |
} | |
#endregion | |
} | |
public class ValidationErrorViewModel | |
{ | |
public ValidationErrorViewModel(string memberName, Func<string, string> getMessage) | |
{ | |
MemberName = memberName.Underscore().Dasherize(); | |
Message = getMessage(memberName); | |
} | |
public string MemberName { get; private set; } | |
public string Message { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment