title: Receive an array of json objects and validate in the controller
body: <p>I'm sending a JSON like this:</p>
  
  <pre><code>[
  {col1: 'value', col2: 'value'}, 
  {col1: 'value2', col2: 'value2'},
  ...
  ]
  </code></pre>
  
  <p>The action in my controller has a List parameter that is requiring a custom model binder, like this:</p>
  
  <pre><code>public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
          {
              var contentType = controllerContext.HttpContext.Request.ContentType;
  
              String bodyText;
  
              Stream stream = null;
              try
              {
                  stream = controllerContext.HttpContext.Request.InputStream;
                  stream.Seek(0, SeekOrigin.Begin);
                  using (var reader = new StreamReader(stream))
                  {
                      stream = null;
                      bodyText = reader.ReadToEnd();
                  }
              }
              finally
              {
                  if (stream != null)
                      stream.Dispose();
              }
  
              if (string.IsNullOrEmpty(bodyText))
              {
                  return null;
              }
  
              var model = new JavaScriptSerializer().Deserialize&lt;T&gt;(bodyText);
              return model;
  
              // return base.BindModel(controllerContext, bindingContext);
          }
  </code></pre>
  
  <p>It's working, except that it is not considering the data annotations for validations (required, range, etc).</p>
  
  <p>How can I get this working with validation?</p>
  
  <p>UPDATE</p>
  
  <p>Controller Action</p>
  
  <pre><code>[HttpPost]
          public ActionResult ActionName([ModelBinder(typeof(JsonArrayValidationModelBinder&lt;List&lt;EntityName&gt;&gt;))]List&lt;EntityName&gt; viewModel)
  </code></pre>
  
  <p>Entity</p>
  
  <pre><code>public class EntityName
  {
          [Display(Name = "Data Entrada")]
          [DataType(DataType.Date)]
          [Required]
          public DateTime? DataEntrada { get; set; }
  // ....
  }
  </code></pre>