title: Refresh bootstrap-datepicker after page load
body: <p>I have an MVC application with a vertical navigation bar and a main page. On the navbar there is a <a href="https://github.com/uxsolutions/bootstrap-datepicker" rel="nofollow noreferrer">bootstrap-datepicker</a>:</p>
  
  <pre><code>@using Mattinale.Domain.Entities
  @using Mattinale.WebUI.Models
  @model MattinaleViewModel
  
  &lt;script type="text/javascript"&gt;
      $(document).ready(function () {
          $('#calendarioMattinale').datepicker({
              todayBtn: "linked",
              language: "it",
              todayHighlight: true
          })
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>By selecting any date on the datepicker, an action method on the main page controller is called by routing:</p>
  
  <pre><code>$(document).ready(function () {
      $('#calendarioMattinale').on('changeDate', function (e) {
          anno = e.date.getYear() + 1900;
          mese = e.date.getMonth() + 1;
          giorno = e.date.getDate();
          window.location.href = '/' + anno + '/' + mese + '/' + giorno;
      })
  });
  </code></pre>
  
  <p>The problem is that when the page is loaded, the selection on the newly selected date is cleared. I've tried to modify the initialization script by adding an update method</p>
  
  <pre><code>$(document).ready(function () {
      $('#calendarioMattinale').datepicker({
          todayBtn: "linked",
          language: "it",
          todayHighlight: true
      })
      dataSelezionata = @Model.GetDataSelezionata();
      $('#calendarioMattinale').datepicker('update', dataSelezionata);
  });
  </code></pre>
  
  <p>but now the controller doesn't even get initialized.</p>
  
  <p>Thanks,
  Davide.</p>