1

I have specified date format as dd/mm/yyyy for telerik datepicker. However, it is recognized as mm/dd/yyyy only. For example, if i enter date as 18/10/2012 error on saving record is thrown as date format is not valid as date entered here as 18 is treated as month. I have defined view for date as:

@model DateTime?           
@(Html.Telerik().DatePickerFor(m => m)
  .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))      
  .Format("dd/MM/yyyy")
  .HtmlAttributes(new { id = ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty) + "_wrapper" })
  .InputHtmlAttributes(new {style="width:160px;"}))

And in model validation for date field is defined as:

[Required(ErrorMessage = "Date Required")]
[DataType(DataType.Date)]
public DateTime? DATE_CALL { get; set; }

Also, in grid has defined column as:

col.Bound(r => r.DATE_CALL).Format("{0:dd/MM/yyyy}").Title("DATE_CALL").Width(170);

So, can't figure out what the error is? Any help will be appreciated.

4

1 回答 1

0

在保存到数据库之前,使用以下设置您的日期格式:

DateTime.ParseExact(<yourDate>, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);
于 2012-10-19T10:13:39.180 回答