0

I am developing a web based application with MVC razor and i'm using Jquery datepicker a couple date field now datepicker load and open correctly but not change date value.i'm calling a partial view for edit using by jquery dialog.Actually if i make edit operation inside page(using query dialog use without partial view), everything is normally.

EditDate.cshtml

<script type="text/javascript">
    $(function () {
        $(".datepicker").datepicker({
            dateFormat: 'dd.mm.yy',
            changeMonth: true,
            changeYear: true,
            yearRange: "-100:+0"
        });
    });
</script>

@using (Html.BeginForm("EditDate", "Home"))
{
    @Html.HiddenFor(m => m.Id)
    @Html.TextBoxFor(m => m.Date, new { @class = "datepicker" })
    <button>Update</button>
}

1 Answer 1

1

If you load this partial view with AJAX chances are that the $(function() { ... }) that you put inside won't be invoked and thus not attaching the plugin to the input field.

I would start by moving this javascript where it belongs: to a separate javascript file and not inside HTML views. I would also put this inside a named function:

function applyDatePickers() {
    $(".datepicker").datepicker({
        dateFormat: 'dd.mm.yy',
        changeMonth: true,
        changeYear: true,
        yearRange: "-100:+0"
    });
}


$(function () {
    applyDatePickers(); // This is only for the initial DOM when the page is loaded
});

and then once you load the jQuery dialog from the server call the applyDatePickers function again. If you are using AJAX to load this partial, that would probably be inside the success callback of your AJAX request.

Sign up to request clarification or add additional context in comments.

1 Comment

Darin, i has tried as you say, i seperated function and i put it on main page but problem still continue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.