title: How can I send selected date from datepicker to a controller?
body: <p>how can I use this piece of jquery code to grab the date from a datePicker when the user selects a date, then send the date as a string to the controller using BeginForm()? How do I access the code between the  tags to use with my razor and asp.net code?</p>
  
  <p>Here’s what I’ve tried from following some tips on the forum but with no luck.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
      $(function () {
          onSelect: Function(dateText, inst); 
          {
              var theDate = $("#date").datepicker('getDate');
              var dateAsObject = $(this).datepicker('getDate');
          }
  
       String selectedDate"";
      selectedDate=theDate.toString();
  
  
           });
  </code></pre>
  
  <p>So after the suggestions I’ve been trying to do this:</p>
  
  <pre><code>    &lt;script type="text/javascript"&gt;
          $(function () {      
                  $(".datepicker").datepicker({dateFormat: 'yy.mm.dd'})
          });  
          &lt;/script&gt;
  
  @using (Html.BeginForm("Action", "Controller",  new { @id = "formName", @Name = "formName" }))
  {
   Date: &lt;input type="text" class="datepicker" onchange="$('#formName').submit();"
   }
  </code></pre>
  
  <p>Then in the controller: </p>
  
  <pre><code>public ActionResult myMethod(DateTime?  date=null)
  {
  if if (date != null)
              { 
              //do 
              }
  }
  </code></pre>
  
  <p>In the controller, date is always null.  Am I naming my GeginForm wrong?</p>