Skip to content

Instantly share code, notes, and snippets.

@davidfowl
davidfowl / MinimalAPIs.md
Last active May 1, 2024 20:58
Minimal APIs at a glance
@regisdiogo
regisdiogo / Startup.cs
Last active June 13, 2022 11:17
ASP.NET Core - Json serializer settings Enum as string and ignore null values
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;
});
}
@jpoehls
jpoehls / get_modelstate_errors.cs
Created March 28, 2012 20:30
Get dictionary of errors from ModelState in ASP.NET MVC
var errorList = ModelState
.Where(x => x.Value.Errors.Count > 0)
.ToDictionary(
kvp => kvp.Key,
kvp => kvp.Value.Errors.Select(e => e.ErrorMessage).ToArray()
);