title: MVC JQuery Datepicker fails to fire after jquery hides and shows the date field
body: <p>In MVC I use an Editor Template in the shared folder for my views to activate the datepicker.
  So my Date.cshtml looks like this;</p>
  
  <pre><code>@model DateTime?
  @Html.TextBox("", Model.HasValue ? Model.Value.ToLongDateString() : string.Empty,
      new { @class = "datefield", type = "date", style = "width:200px;" })
  </code></pre>
  
  <p>And in my view I have;</p>
  
  <pre><code>&lt;td class="rightCell"&gt;
      @Html.EditorFor(model =&gt; model.Assessment.SsipAccreditationDate)
      @Html.ValidationMessageFor(
                      model =&gt; model.Assessment.SsipAccreditationDate, "*")
  &lt;/td&gt;
  </code></pre>
  
  <p>This field is defined in the View Model as </p>
  
  <pre><code>    [DataType(DataType.Date)]
      [DisplayName("SSIP Accreditation Date")]
      public DateTime? SsipAccreditationDate { get; set; }
  </code></pre>
  
  <p>And the script that joins it up is this;</p>
  
  <pre><code>var initialiseDate = function() {
      $(".datefield").datepicker({
          showOn: "both",
          dateFormat: "dd MM yy",
          changeMonth: true,
          changeYear: true
      }).next("button.ui-datepicker-trigger")
              .attr("tabIndex", "-1");
  }
  </code></pre>
  
  <p>And the problem is that the datepicker only pops up when there is a date already in there. If the field is null, it does not popup.</p>
  
  <p>In ie developer tools, the markup for the field looks like this;</p>
  
  <pre><code>&lt;input name="Assessment.SsipAccreditationDate" class="datefield hasDatepicker" id="Assessment_SsipAccreditationDate" style="width: 200px;" type="date" value="" data-val="true" data-val-date="The field SSIP Accreditation Date must be a date."&gt;
  &lt;button tabindex="-1" class="ui-datepicker-trigger" type="button"&gt;...&lt;/button&gt;
  &lt;span class="field-validation-valid" data-valmsg-replace="false" data-valmsg-for="Assessment.SsipAccreditationDate"&gt;*&lt;/span&gt;
  </code></pre>
  
  <p>So what is going wrong?</p>
  
  <p>EDIT - a key part of the problem is that in jquery I show and hide the date and that seems to make the difference. On another page I do not have this problem with this date field.</p>