How can I centralize modelstate validation in asp.net mvc using action filters?

If you want to do this in MVC6 or Mvc Core and without specifying your attribute on all of your Action methods then this is how you do it.

First create your ActionFilter

public class ModelStateValidationFilterAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting( ActionExecutingContext context )
    {
        if ( context.HttpContext.Request.Method == "POST" && !context.ModelState.IsValid )
            context.Result = new BadRequestObjectResult( context.ModelState );
    }
}

Now create a convention in which you will apply this ActionFilter to all of your controllers.

    public class ModelStateValidatorConvension : IApplicationModelConvention
    {
        public void Apply( ApplicationModel application )
        {
            foreach ( var controllerModel in application.Controllers )
            {
                controllerModel.Filters.Add( new ModelStateValidationFilterAttribute() );
            }
        }
    }

And the last thing is to register this convention in MVC

    public void ConfigureServices( IServiceCollection services )
    {
      services.Configure<MvcOptions>( x => x.Conventions.Add( new ModelStateValidatorConvension() ) );
    }

To conform with REST, you should return http bad request 400 to indicate that the request is malformed (model is invalid) instead of returning Json(false).

Try this attribute from asp.net official site for web api:

public class ValidateModelAttribute : ActionFilterAttribute
{
     public override void OnActionExecuting(HttpActionContext actionContext)
     {
        if (!actionContext.ModelState.IsValid)
        {
            actionContext.Response = actionContext.Request.CreateErrorResponse(
                HttpStatusCode.BadRequest, actionContext.ModelState);
        }
    }
}

A version for asp.net mvc could be like this:

public class ValidateModelAttribute : ActionFilterAttribute
{
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
              if (!filterContext.Controller.ViewData.ModelState.IsValid)
              {
                   filterContext.Result = new HttpStatusCodeResult(HttpStatusCode.BadRequest);  
              }
        }
}