mvc Datepicker to model

Asked by At

i have this javascript code to show up datepicker and select the month/year of the selected day.

<script type="text/javascript">
    $(document).ready(function () {
            dateFormat: 'MM/yy',
            changeMonth: true,
            changeYear: true,
            showButtonPanel: true,

            onClose: function (dateText, inst) {
                var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
                var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
                $(this).val($.datepicker.formatDate('MM/yy', new Date(year, month, 1)));

        $(".monthPicker").focus(function () {
                my: "center top",
                at: "center bottom",
                of: $(this)

and now, i want to pass this date to the model, how can i do it ? when i choose the day, my textbos show : (month/year)

this is my view and my viewmodel.

public Nullable<System.DateTime> Month { get; set; }

<div class="form-group">
                    @Html.LabelFor(m => m.Month, new { @class = "control-label col-sm-3" })
                    <div class="col-sm-9 input-group">

                        <input  class="monthPicker" />

                        @Html.ValidationMessageFor(model => model.Month, "", new { @class = "text-danger " })

0 Answers