title: how to model bind form urlencoded data to .net class
body: <p>We have a 3rd party vendor posting data to us in the following format.  Unfortunately this is the only format they offer.  Json would be nice, but we don't have a choice.  It's hitting a .net core webapi controller method.</p>
  
  <pre><code>contact%5Bid%5D=2&amp;contact%5Bemail%5D=test@test.com&amp;contact%5Bfirst_name%5D=john&amp;contact%5Blast_name%5D=smith
  </code></pre>
  
  <p>The controller method looks like this.</p>
  
  <pre><code>public IActionResult Endpoint([FromForm] customClass)
  {
      //do something with customClass
      return Ok();
  }
  </code></pre>
  
  <p>The class would be something like</p>
  
  <pre><code>using System;
  using System.Runtime.Serialization;
  
  namespace Domain.Models.Custom
  {
      [DataContract]
      public class CustomClass
      {
          [DataMember(Name = "contact[id]")]
          public int Id { get; set; }
  
          [DataMember(Name = "contact[first_name]")]
          public string FirstName { get; set; }
  
          [DataMember(Name = "contact[last_name]")]
          public string LastName { get; set; }
  
          [DataMember(Name = "contact[phone]")]
          public string PhoneNumber { get; set; }
  
          [DataMember(Name = "contact[email]")]
          public string EmailAddress { get; set; }
      }
  }
  </code></pre>
  
  <p>From everything I've read it sounds like decorating the class with the DataContract and DataMember attributes should to the model binding for me.  But when I look at the instance of customClass in the Endpoint method all the properties are null.</p>