Skip to content

Instantly share code, notes, and snippets.

@explorer14
Created March 3, 2019 20:40
Show Gist options
  • Save explorer14/ab6a02c2cd35cd106c5c5460f282f645 to your computer and use it in GitHub Desktop.
Save explorer14/ab6a02c2cd35cd106c5c5460f282f645 to your computer and use it in GitHub Desktop.
public class ModelBindingFailureFilterSimple : IActionFilter
{
public void OnActionExecuted(ActionExecutedContext context)
{
}
public void OnActionExecuting(ActionExecutingContext context)
{
if (!context.ModelState.IsValid)
{
context.Result = new BadRequestObjectResult(
context
.ModelState
.ToDictionary(
x=>x.Key,
y=>y.Value.Errors.Select(
z=>z.Exception.Message).ToList()));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment