Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thiagoloureiro/78817fca7862be8eeb6b484f1fe8a162 to your computer and use it in GitHub Desktop.
Save thiagoloureiro/78817fca7862be8eeb6b484f1fe8a162 to your computer and use it in GitHub Desktop.
public class ModelStateValidationActionFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
var modelState = actionContext.ModelState;
if (!modelState.IsValid)
actionContext.Response = actionContext.Request
.CreateErrorResponse(HttpStatusCode.BadRequest, modelState);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment