title: ASP.Net MVC and jQuery DatePicker ViewModel
body: <p>I have a DatePicker working on a View which also has a ViewModel associated with it.
  When I execute the Post action back to the controller the ViewModel is instantiated again and some of the values are not available from the View.</p>
  
  <p>The Controller Action is:</p>
  
  <pre><code>    public ActionResult Search()
      {
          ProjectSearchViewModel viewModel = 
              new ProjectSearchViewModel(
                  DateTime.Today.AddMonths(-1), 
                  DateTime.Today.AddDays(1));
  
          return View(viewModel);
      }
  
    [AcceptVerbs(HttpVerbs.Post)]
      public ActionResult Search(ProjectSearchViewModel viewModel)
      {
          try
          {
              //Always returns a value from UI
              DateTime startDate = viewModel.StartDate; 
              //NEVER returns a Value from UI
              DateTime endDate = viewModel.EndDate; 
  </code></pre>
  
  <p>.....</p>
  
  <p>The View markup is:</p>
  
  <p><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/TabbedViewMasterPage.master"
      Inherits="System.Web.Mvc.ViewPage&lt;Reactivity.Web.Models.ProjectSearchViewModel&gt;"</code>%></p>
  
  <p>...</p>
  
  <pre><code> &lt;label for="StartDate"&gt;
          Start Date:
      &lt;/label&gt;
      &lt;% Html.jQuery().DatePicker()
              .Name("StartDate")
              .AllowMonthChange(true)
              .AllowYearChange(true)
              .ShowOn(DatePickerShowOn.Focus)
              .ShowOtherMonths(true)
              .Value(ViewData.Model.StartDate)
              .Render(); %&gt;
      &lt;br /&gt;
      &lt;label for="EndDate"&gt;
          End Date:
      &lt;/label&gt;
      &lt;% Html.jQuery().DatePicker()
              .Name("EndDate")
              .AllowMonthChange(true)
              .AllowYearChange(true)
              .ShowOn(DatePickerShowOn.Focus)
              .ShowOtherMonths(true)
              .Value(ViewData.Model.EndDate)
              .Render(); %&gt;
      &lt;br /&gt;
      &lt;input type="submit" value="Search" /&gt;
  </code></pre>
  
  <p>The DatePicker (two instances on View) work fine.</p>
  
  <p>How do I ensure the ViewModel fields (viewModel.EndDate) are returned populated to the Controller Action? Or is this an issue with having two (MVC) DatePickers on the form?</p>
  
  <p>Many thanks
  Brian</p>