Reputation: 4873
I am using KendoDatePicker, I use this all over my application. However, I am suddenly having an issue with it passing dates in wrong format.
@(Html.Kendo().DatePicker()
.Name("ToDate")
.Min(DateTime.Today.AddYears(-1)) //Set the min date of the DatePicker.
.Max(DateTime.Today) //Set the min date of the DatePicker.
.Value(DateTime.Today.ToString("dd/MM/yyyy")) // I have also just set DateTime.Today, without formating as string
)
I use the following JS function to retrieve the date from the date picker:
function getDatePickerValue() {
var toDate= $("#ToDate").val();
return {
transactionToDate: toDate
}
}
I then pass this value to my controller, which takes the date and filters a grid. This is what is being passed (as seen in my Network debugger): transactionToDate:"01/04/2016"
This is my controller method
public JsonResult GetCustomerElectronicTransactions([DataSourceRequest] DataSourceRequest request, DateTime? transactionToDate){}
My controller is recognizing the date as MM/DD/YYYY, but it actually being passed as DD/MM/YYYY, so what is happening is that my Months and Days are being switch when passed.
Does anyone have any suggestion? I don't understand why this is suddenly giving me an issue, I've used this exact setup in other controller/views without an issue.
Thoughts?
Upvotes: 2
Views: 1585
Reputation: 4873
The problems was to do with the way I was getting the value of the datepicker in JS.
I changed :
function getDatePickerValue() {
var toDate= $("#ToDate").val();
return {
transactionToDate: toDate
}
}
To:
function getDatePickerValue() {
var toDate= $("#ToDate").data("kendoDatePicker").value();
return {
transactionToDate: toDate
}
}
Upvotes: 1