We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

assign values to datepicker in Ajax success function

Thread ID:

Created:

Updated:

Platform:

Replies:

142603 Feb 12,2019 02:57 AM UTC Feb 12,2019 11:57 AM UTC ASP.NET MVC - EJ 2 1
loading
Tags: DatePicker
jsu
Asked On February 12, 2019 02:57 AM UTC

Hi Team,

Could you please advise how to assign min, value and max property values to datepicker in Ajax success function?
I tried below code but the appendTo code creates new datepicker controller each time the Ajax success function fires, see screenshot.

var currentYear = today.getFullYear(); var currentMonth = today.getMonth(); var currentDay = today.getDate(); var datepicker = new ej.calendars.DatePicker({ min: new Date(currentYear, currentMonth, 7), max: new Date(currentYear, currentMonth, 27), value: new Date(currentYear, currentMonth, 14) }); datepicker.appendTo('#datepicker');


Thanks

Christopher Issac Sunder K [Syncfusion]
Replied On February 12, 2019 11:57 AM UTC

Hi Customer, 

Thank you for contacting Syncfusion support. 

We have prepared the sample for assign the min and max values to the DatePicker component on AJAX success method. Please check with the below code example. 

[index.cshtml] 
<div> 
    <input type="text" id="datepicker" />   
    <div> 
        <input type="button" id="btnGet" value="Submit" /> 
    </div> 
</div> 
 
<script> 
    var today = new Date(); 
    var currentYear = today.getFullYear(); 
    var currentMonth = today.getMonth(); 
    var currentDay = today.getDate(); 
 
    //DatePicker creation 
    var datepicker = new ej.calendars.DatePicker({ 
        min: new Date(currentYear, currentMonth, 7), 
        max: new Date(currentYear, currentMonth, 27), 
        value: new Date(currentYear, currentMonth, 14), 
        width: "250px" 
    }); 
    datepicker.appendTo('#datepicker'); 
 
    // Ajax method to set the min and max value 
    $(function () { 
        $("#btnGet").click(function () { 
            $.ajax({ 
                type: "POST", 
                url: "/Home/AjaxMethod", 
                data: '{}', 
                contentType: "application/json; charset=utf-8", 
                dataType: "json", 
                success: function (response) { 
                    // Create the instance for the DatePicker 
                    var dateObj = document.getElementById('datepicker').ej2_instances[0]; 
                    // Assign the min and max value to DatePicker 
                    dateObj.min = new Date(parseInt(response.min.substr(6))); 
                    dateObj.max = new Date(parseInt(response.max.substr(6))); 
                } 
            }); 
        }); 
    }); 
</script> 
 

        
[HomeController.cs] 
 
       public class Datemodel 
        { 
            ///<summary> 
            /// Gets or sets min. 
            ///</summary> 
            public DateTime? min { get; set; } 
 
            ///<summary> 
            /// Gets or sets max. 
            ///</summary> 
            public DateTime? max { get; set; } 
        } 
 
        [HttpPost] 
        public JsonResult AjaxMethod(DateTime? min, DateTime? max) 
        { 
            // pass the min and max values to the component 
            Datemodel model = new Datemodel 
            { 
                min = DateTime.Parse("2/1/2019"), 
                max = DateTime.Parse("3/10/2019") 
            }; 
            return Json(model); 
        } 

Please check the sample from the below link. 

 
Please let us know if you require any further assistance. 

Thanks, 
Christo 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;