title: jquery date picker disable specific dates from db in MVC
body: <p>I want to disable dates in jquery calender fetched from db but facing an issue. Here is my code.</p>
  
  <pre><code>$(function () {
      getdates();
  });
  
  var unavailableDates;
  function getdates() {
      $.ajax({
          type: "POST",
          url: "/DisableDates/GetDatesArray",
          data: '',
          success: function (data) {
              debugger;
              unavailableDates = data;
          },
          dataType: "json",
          traditional: true
      });
  }
  
  $("#pickdate").datepicker({
      dateFormat: 'dd-mm-yyyy',
      beforeShowDay: function (date) {
          var dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
          debugger;
          if ($.inArray(dmy, unavailableDates) == -1) {
              return [true, ""];
          } else {
              return [false, "myclass", "Unavailable"];
          }
      }
  });
  </code></pre>
  
  <p>After fetching data from db I keep it in variable "unavailableDates" but when try to find in "beforeShowDay" event of date picker, its throwing error "undefined".</p>
  
  <p>Here is the controller code</p>
  
  <pre><code>public ActionResult GetDatesArray()
  {
      List&lt;string&gt; list = new List&lt;string&gt;();
      list.Add("25-12-2014");
      list.Add("26-12-2014");
      list.Add("27-12-2014");
      return Json(list.ToArray(), JsonRequestBehavior.AllowGet);
  }
  </code></pre>
  
  <p>Any ideas?</p>