I want to exclude the time part in the DateTime Textbox, but I can\'t make it work the way I want.
This is how I set up the field :
@H
The reason why you date is not being correctly bound is that your datepicker is using dd/MM/yyy format, but you server is using MM/dd/yyyy format. To make this work, you can create a custom model binder to handle DateTime values and parse them to the format you want.
public class CustomDateTimeBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
CultureInfo culture = new CultureInfo("en-GB"); // dd/MM/yyyy
var date = value.ConvertTo(typeof(DateTime), culture);
return date;
}
}
and register it in Global.asax (this means it will apply to all DateTime values
ModelBinders.Binders.Add(typeof(DateTime), new YourAssembly.CustomDateTimeBinder());