ASP.NET MVC datetimepicker change event

ASP.NET MVC datetimepicker change event


In ASP.NET MVC Application, we needed a solution to trigger an change event only if the date changed. (bootstrap-datetimepicker.min.js onchange)


You can use the following code snippet to trigger the change event of the datetimepicker field


$('#date').datetimepicker().on('dp.change', function (e) fires whenever a date is selected.


To detect the change event, use :

<script type="text/javascript">

    $(document).ready(function () {
        $('#date').datetimepicker().on('dp.change', function (e) {
            var val1 = $("#date").val();
            console.log("Date : " + val1);
        });

    });

</script>

tag : bootstrap-datetimepicker.min.js onchange,ASP.NET MVC datetimepicker


That will only fire change for a new value.


It's triggered when the "date" field is changed using the keyboard.


How to use datettimepicker in ASP.NET MVC


Index.cshtml


<div class="col-12 col-md-6">
    <div class="form-group">
        <label>Date</label>
        <div class="cal-icon">
            @Html.TextBoxFor(m => m.date, new { @class = "form-control datetimepicker", type = "text" })
            @Html.ValidationMessageFor(m => m.date)
        </div>
    </div>
</div>

datetimepicker_2.png

datetimepicker_1.png