May 18, 2020

Binding and Validating Enums in ASP.NET Core

We commonly use C# Enumeration types to represent a set of named constants within our applications. Often the values for such properties comes from the user via an API request but unfortunately the default model-binding and validation behavior in ASP.NET Core does provide the desired API experience. This post looks at how we handle binding and validating enum values in our APIs as well as supporting snake_case variants of the enum member names.

© 2022 Ben Foster