This document now exists on the official ASP.NET core docs page.
- Application
- Request Handling
This document now exists on the official ASP.NET core docs page.
public class Startup | |
{ | |
public IServiceProvider ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMvc().AddJsonOptions(options => | |
{ | |
options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); | |
options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; | |
}); | |
} |
var errorList = ModelState | |
.Where(x => x.Value.Errors.Count > 0) | |
.ToDictionary( | |
kvp => kvp.Key, | |
kvp => kvp.Value.Errors.Select(e => e.ErrorMessage).ToArray() | |
); |