Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save motowilliams/1307763 to your computer and use it in GitHub Desktop.

Select an option

Save motowilliams/1307763 to your computer and use it in GitHub Desktop.
Extension-Methods-Improving-the-quality-of-Life
public static class ModelStateExtensions
{
public static void AddModelErrors(this ModelStateDictionary values, IEnumerable<ValidationResult> validationResults)
{
foreach (var validationResult in validationResults)
values.AddModelError(validationResult.MemberNames.FirstOrDefault(), validationResult.ErrorMessage);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment