Created
March 3, 2019 20:40
-
-
Save explorer14/ab6a02c2cd35cd106c5c5460f282f645 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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