Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7959639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:36:20+00:00 2026-06-04T04:36:20+00:00

I need to pass list/json/array of dates information to a Jquery UI Datepicker dynamically

  • 0

I need to pass list/json/array of dates information to a Jquery UI Datepicker dynamically through a jsonresult in a MVC controller.

Following the link below, I am able to highlight selected dates in the datepicker control.
http://jquerybyexample.blogspot.com/2012/05/highlight-specific-dates-in-jquery-ui.html

    < script type ="text/javascript">
    $(document).ready( function () {

    var SelectedDates = {};
    SelectedDates[ new Date('05/28/2012' )] = new Date( '05/28/2012' );
    SelectedDates[ new Date('05/29/2012' )] = new Date( '05/29/2012' );
    SelectedDates[ new Date('05/30/2012' )] = new Date( '05/30/2012' );
    //want to replace the above three lines with code to get dates dynamically
    //from controller

    $( '#releasedate' ).datepicker({
        dateFormat: "mm/dd/yy" ,
        numberOfMonths: 3,
        duration: "fast" ,           
        minDate: new Date(),
        maxDate: "+90" ,
    beforeShowDay: function (date) {
        var Highlight = SelectedDates[date];
        if (Highlight) {
            return [true , "Highlighted", Highlight];
        }
        else {
            return [true , '', '' ];
        }
    }
});

The above code will highlight those specific three dates on the calendar control(UIDatepicker).Instead of hard coding dates like above… My challenge is to get these dates dynamically from a controller and pass it on to the var SelectedDates in javascript above.

Controller jsonresult code:

  public JsonResult GetReleasedDates(string Genre)
{

    var relDates = service.GetDates(Genre)//code to get the dates here

    return Json(relDates, JsonRequestBehavior .AllowGet);

    //relDates will have the dates needed to pass to the datepicker control.

}

Thanks for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:36:20+00:00Added an answer on June 4, 2026 at 4:36 am

    The first possibility is to use a model that will be directly serialized into JSON:

    public ActionResult Index()
    {
        // TODO: obviously those will come from your service layer
        var selectedDates = new Dictionary<string, DateTime> 
        { 
            { 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);
    }
    

    and in the view:

    @model IDictionary<string, DateTime>
    
    <script type ="text/javascript">
        $(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, '', ''];
                    }
                }
            });
        });
    </script>
    

    The other possibility is to use AJAX to retrieve the selectedDates later:

    public ActionResult Index()
    {
        return View();
    }
    
    public ActionResult GetSelectedDates()
    {
        // TODO: obviously those will come from your service layer
        var selectedDates = new Dictionary<string, DateTime> 
        { 
            { 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);
    }
    

    and then:

    <script type ="text/javascript">
        $(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, '', ''];
                        }
                    }
                });
            });
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to pass array list to SOAP service: var arrayList = new ArrayList
I need to pass a list of strings as parameter to a console application
i need to pass a long list of Ids from one page to another,
I have a list of strings that I need to pass to a process
I have a list of integers or of strings and need to pass it
I need to pass a pointer through a scripting language which just has a
to initialize a javascript loaded grid, I need to pass a list of values
I need to pass a list of Days (number and name) to an view!
I need to pass a list to a KornShell (ksh) function, something like this:
I'm uwsing MVC and jqgrid and I need to pass a value from dropdownlist

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.