Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
function RaceDate_onChange() {
    var pickedDate = $(this).data('tDatePicker').value();
    var month = pickedDate.getMonth() + 1;
    $.get("/RaceCard/Details?year=" + pickedDate.getFullYear() + "&month=" + month + "&day=" + pickedDate.getDate());
}
@Html.Telerik().DatePickerFor(model => model.RaceDate).ClientEvents(events => events.OnChange("RaceDate_onChange"))

[HttpGet]
public ActionResult Details(int year, int month, int day)
{
    var viewModel = new RaceCardModel { Metadata = DetailModelMetadata.Display, RaceDate = new DateTime(year, month, day) };
    var raceCard = _raceCardService.GetByRaceDate(viewModel.RaceDate) ?? new RaceCard { RaceDate = DateTime.Now };
    viewModel.MapFromEntity(raceCard);
    return View(viewModel);
}


In the above JavaScript even handler, Telerik MVC DatePicker, and controller action respectively, in GET requests to the Details action, the day value is always one day behind the DatePicker. E.g. The first value is set from a view model property, when the view is rendered, say 3. I then click on 14 and hit my breakpoint in the action method. The day value is 3. When I click on 29 and hit the breakpoint, the day value is 14.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900