In the latest .NET Core 2.1, an automatic validation for the model state validation is introduced (https://blogs.msdn.microsoft.com/webdev/2018/02/02/asp-net-core-2-1-roadmap/#mvc).
Previously I could override the validation error response by the following code below:
public class ApiValidateModelAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext context)
{
if (!context.ModelState.IsValid)
{
context.Result = new BadRequestObjectResult(new context.ModelState);
}
base.OnActionExecuting(context);
}
But now it no longer works. The validation errors is responded without entering the override method.
Anyone has any clue? Thanks.