I'm having a problem when submitting the date to a controller.
The Date is sent in JSON Date format (ex: /Date(1456592400000)/)
. Then using Knockout custom binding and momentjs, the date is converted into the 'DD/MM/YYYY'
format.
The datepicker is showing the date correctly as '28/02/2016'
, but when I send it back to the Controller the date value is '01/01/0001 0:00:00'
which caused the model to be invalid.
Before submitted, I checked the console and the date is "2016-02-27T17:00:00.000Z"
. But if I don't use Knockout custom binding and just use the value binding, it works.
I try to modify the model binder to format the date, as described in this post, but it still doesn't work.
public class DateTimeBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
bindingContext.ModelState.SetModelValue(bindingContext.ModelName, value);
return value.ConvertTo(typeof(DateTime), CultureInfo.CurrentCulture);
}
}
I've set the culture id-ID in the web.config
<globalization uiCulture="id-ID" culture="id-ID" />
How do I solve this problem? Here is the jsfiddle to describe the problem.