Skip to content

Instantly share code, notes, and snippets.

@thefringeninja
Created January 2, 2014 23:46
Show Gist options
  • Save thefringeninja/8229585 to your computer and use it in GitHub Desktop.
Save thefringeninja/8229585 to your computer and use it in GitHub Desktop.
Validation Errors
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