title: MVC WebApi Get passing an object in C#
body: <p>I need to get a from and to date to my mvc webapi for retrieving items between those dates.  Here is my favorite thing I have tried that has not worked (I have tried several things).</p>
  
  <p>I have an object that is shared between the projects:</p>
  
  <pre><code>public class SchedulerDateSpan
  {
      public DateTime StartDate { get; set; }
      public DateTime EndDate { get; set; }
  }
  </code></pre>
  
  <p>Here is my controller class for get:</p>
  
  <pre><code>public IEnumerable&lt;Appointment&gt; GetAppointments(SchedulerDateSpan dates)
  {
     IEnumerable&lt;Appointment&gt; appointments =
     db.Appointments.Where(
     a =&gt;
     (a.StartDate &lt;= dates.StartDate &amp;&amp; a.EndDate &gt;= dates.StartDate) || (a.StartDate &lt;= dates.EndDate &amp;&amp; a.EndDate &gt;= dates.EndDate) ||
     (a.StartDate &gt; dates.StartDate &amp;&amp; a.EndDate &lt; dates.EndDate)).AsEnumerable();
     return appointments;
  }
  </code></pre>
  
  <p>Here is my call from the client where dates is of type SchedulerDateSpan:</p>
  
  <pre><code>var client = new HttpClient { BaseAddress = new Uri(Properties.Settings.Default.SchedulerWebApi) };
  
  client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
  HttpResponseMessage resp = client.GetAsync(String.Format("api/Appointments/{0}",dates)).Result;
  
  if (resp.IsSuccessStatusCode)
  { 
     var appointments = resp.Content.ReadAsAsync&lt;IEnumerable&lt;Appointment&gt;&gt;().Result;
            ......
  }
  </code></pre>
  
  <p>I also tried changing it to a put which seemed to work but then I couldn't parse the results with <code>Content.ReadAsAsync</code></p>
  
  <p>Any suggestions are appreciated</p>