Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The first possibility is to use a model that will be directly serialized into JSON:</p> <pre><code>public ActionResult Index() { // TODO: obviously those will come from your service layer var selectedDates = new Dictionary&lt;string, DateTime&gt; { { new DateTime(2012, 5, 28).ToString("yyyy-M-dd"), new DateTime(2012, 5, 28) }, { new DateTime(2012, 5, 29).ToString("yyyy-M-dd"), new DateTime(2012, 5, 29) }, { new DateTime(2012, 5, 30).ToString("yyyy-M-dd"), new DateTime(2012, 5, 30) }, }; return View(selectedDates); } </code></pre> <p>and in the view:</p> <pre><code>@model IDictionary&lt;string, DateTime&gt; &lt;script type ="text/javascript"&gt; $(document).ready(function () { var selectedDates = @Html.Raw(Json.Encode(Model)); $('#releasedate').datepicker({ dateFormat: "mm/dd/yy", numberOfMonths: 3, duration: "fast", minDate: new Date(), maxDate: "+90", beforeShowDay: function (date) { var key = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate(); var highlight = selectedDates[key]; if (highlight) { return [true, "Highlighted", highlight]; } else { return [true, '', '']; } } }); }); &lt;/script&gt; </code></pre> <p>The other possibility is to use AJAX to retrieve the <code>selectedDates</code> later:</p> <pre><code>public ActionResult Index() { return View(); } public ActionResult GetSelectedDates() { // TODO: obviously those will come from your service layer var selectedDates = new Dictionary&lt;string, DateTime&gt; { { new DateTime(2012, 5, 28).ToString("yyyy-M-dd"), new DateTime(2012, 5, 28) }, { new DateTime(2012, 5, 29).ToString("yyyy-M-dd"), new DateTime(2012, 5, 29) }, { new DateTime(2012, 5, 30).ToString("yyyy-M-dd"), new DateTime(2012, 5, 30) }, }; return Json(selectedDates, JsonRequestBehavior.AllowGet); } </code></pre> <p>and then:</p> <pre><code>&lt;script type ="text/javascript"&gt; $(document).ready(function () { $.getJSON('@Url.Action("GetSelectedDates")', function(selectedDates) { // Only inside the success callback of the AJAX request you have // the selected dates returned by the server, so it is only here // that you could wire up your date picker: $('#releasedate').datepicker({ dateFormat: "mm/dd/yy", numberOfMonths: 3, duration: "fast", minDate: new Date(), maxDate: "+90", beforeShowDay: function (date) { var key = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate(); var highlight = selectedDates[key]; if (highlight) { return [true, "Highlighted", highlight]; } else { return [true, '', '']; } } }); }); }); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload