Hello,
I am a beginner with kendo UI and have a problem with the following input box:
<
input
data-role
=
"datepicker"
data-format
=
"dd.MM.yyyy"
data-bind
=
"enabled: isEnabled, value: DateToSave"
/>
The date is picked correctly (displayed on the page), but after saving to the server the value in the server table is one day off. The displayed value on the page (after saving) is also one day off from the picked value.
These are the project infos:
- Telerik ASP.NET MVC 4 (v2013.3.1119)
- culture: "de-AT"
editorTemplate and DateTimeModelBinder
@model DateTime?
<div
class
=
"span-datepricker"
>
<input name=
"datepicker"
/>
</div>
<script>
$(document).ready(function () {
// create DatePicker from input HTML element
$(
"input[name='datepicker']"
).kendoDatePicker();
});
</script>
using
System;
using
System.Globalization;
using
System.Web.Mvc;
namespace
Presentation.Host.App_Start
{
public
class
DateTimeModelBinder : IModelBinder
{
private
const
string
DateTimePattern =
"ddd MMM dd yyyy HH:mm:ss 'GMT'zzz"
;
public
object
BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
string
value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName).AttemptedValue;
if
(!
string
.IsNullOrWhiteSpace(value))
{
int
timeZoneInfoIndex = value.IndexOf(
" ("
, StringComparison.Ordinal);
if
(timeZoneInfoIndex > 0)
{
value = value.Substring(0, timeZoneInfoIndex);
return
DateTime.ParseExact(value, DateTimePattern, CultureInfo.InvariantCulture).AddDays(1);
}
return
DateTime.Parse(value);
}
return
null
;
}
}
}
ViewModel:
.....
public
DateTime? DateToSave {
get
;
set
; }
...
If you could give me some hints where to start looking I'd be thankful.
Best regards.
Manu