title: Using the ValidateModelAttribute with an MVC View in ASP.NET Core 2.1
body: <p>Previously in WebAPI projects I used the <code>ValidateModelAttribute</code> to avoid repeating <code>if (!ModelState.IsValid)</code> statements in each of my controllers.</p>
  
  <pre><code>public class ValidateModelAttribute : ActionFilterAttribute
  {
    public override void OnActionExecuting(ActionExecutingContext context)
    {
      if (!context.ModelState.IsValid)
      {
        context.Result = new BadRequestObjectResult(context.ModelState);
      }
    }
  }
  </code></pre>
  
  <p>When I try to use the same attribute on an action in a MVC controller (ASP.NET Core 2.1) I receive a 400 status code and the page simply displays the JSON representation of the error e.g. <code>{"Description":["Description is required"]}</code>.</p>
  
  <p>Is there a similar attribute I can use in my MVC controllers to forward the ModelState errors to my view in the same way as using</p>
  
  <pre><code>if (!ModelState.IsValid)
  {
    return View(command);
  }
  </code></pre>