Skip to content

Instantly share code, notes, and snippets.

@evgomes
Created January 30, 2019 13:16
Show Gist options
  • Save evgomes/6f747c5f675e86e2f4209163005107bd to your computer and use it in GitHub Desktop.
Save evgomes/6f747c5f675e86e2f4209163005107bd to your computer and use it in GitHub Desktop.
ModelStateExtensions from Supermarket API
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc.ModelBinding;
namespace Supermarket.API.Extensions
{
public static class ModelStateExtensions
{
public static List<string> GetErrorMessages(this ModelStateDictionary dictionary)
{
return dictionary.SelectMany(m => m.Value.Errors)
.Select(m => m.ErrorMessage)
.ToList();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment