title: Handle ModelState Validation in ASP.NET Web API
body: <p>I was wondering how I can achieve model validation with ASP.NET Web API. I have my model like so:</p>
  
  <pre><code>public class Enquiry
  {
      [Key]
      public int EnquiryId { get; set; }
      [Required]
      public DateTime EnquiryDate { get; set; }
      [Required]
      public string CustomerAccountNumber { get; set; }
      [Required]
      public string ContactName { get; set; }
  }
  </code></pre>
  
  <p>I then have a Post action in my API Controller:</p>
  
  <pre><code>public void Post(Enquiry enquiry)
  {
      enquiry.EnquiryDate = DateTime.Now;
      context.DaybookEnquiries.Add(enquiry);
      context.SaveChanges();
  }
  </code></pre>
  
  <p>How do I add <code>if(ModelState.IsValid)</code> and then handle the error message to pass down to the user?</p>