简体   繁体   中英

how to use jquerydate picker with partial views in asp.net mvc?

i am working on asp.net mvc. at staring i used the jquery which works fine but now i am converting my pages in to partial pages at this point am using ajax function to convert it in to partial view but every thing is working fine except date picker plz tell me the solution.

the script that i have used:

                         $(document).ready(function() {
                             $("#txtTransationDate").datepicker();
                         });
                        </script>

<input id="txtTransationDate" name="txtTransationDate" type="text" />

thank you......

Add a class to all of your textboxes that you want to convert to datepicker, like such:

<input class="useDatePicker" id="txtTransationDate" name="txtTransationDate" type="text" />
<input class="useDatePicker" id="txtInvoiceDate" name="txtInvoiceDate" type="text" />
<input class="useDatePicker" id="txtWhateverDate" name="txtWhateverDate" type="text" />

Then in your master page, add this script:

<script type="text/javascript">

    $(document).ready(function () {
        $(".useDatePicker").live('click', function () {
            $(this).datepicker('destroy').datepicker({
                showOn: 'focus'
            }).focus();
        });
    });

</script>

in the success call back of your ajax function set up the calendar.

$.ajax({
    url: url,
    data: yourData, 
    type: 'POST',
    success: function(){
       $("#datepicker").datepicker();

    },
    error: function(){
           //your error stuff
    }
});

something like that should work. i've got calendars in partial views with out any issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM