Created
April 10, 2019 07:47
-
-
Save mattuu/cf7aaa43a07685b2e93a095ec62056ba to your computer and use it in GitHub Desktop.
ValidateModelStateAttribute - adds handing invalid model state and returns BadRequest (400)
This file contains hidden or 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 ValidateModelStateAttribute : ActionFilterAttribute | |
{ | |
public override void OnActionExecuting(ActionExecutingContext context) | |
{ | |
if (!context.ModelState.IsValid) | |
{ | |
context.Result = new BadRequestObjectResult(context.ModelState); | |
} | |
base.OnActionExecuting(context); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment