开发者

Jquery datepicker showing previous date in MVC

开发者 https://www.devze.com 2023-01-10 08:03 出处:网络
I am using the jquery datepicker function on a mvc Html.Textbox, which is bound to my model, the first time I press my search button it gets the correct date in my model, however if I press search aga

I am using the jquery datepicker function on a mvc Html.Textbox, which is bound to my model, the first time I press my search button it gets the correct date in my model, however if I press search again, it should return a different date from the model but it doesn't - it stays cached as the same date that came the first time. I debugged and checked my model contains a new date which it does, but it still shows the old date, I think this is to do with the jquery datepicker setup, how can I stop it from caching this first date?

Here is my MVC code and jquery call:

<%= Html.TextBox("MyDate",Model.listOfLoan[i].MyDate.ToShortDateString(), new {@class = "datep"}) %>   



<script language="te开发者_开发问答xt/javascript" type="text/javascript">
    $(document).ready(function() {
        $('.datep').datepicker({ dateFormat: 'dd/mm/yy' });
    });
</script>

When I debug, the model date has the correct date but it always shows the last date! THanks


David,

Make sure you add $.ajaxSetup({ cache: false }); into your code i.e:

<script language="text/javascript" type="text/javascript">
    $(document).ready(function() {
        $.ajaxSetup({ cache: false });
        $('.datep').datepicker({ dateFormat: 'dd/mm/yy' });
    });
</script>

might make it work for you.

jim

btw - you're obviously setting the datepicker against a range of dates with the datep class. what happens if you set the datepicker by individual ID?


Sorry guys I idenitified this as a different problem, not related to jquery but setup of the id! Doh!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号