nabs
nabs

Reputation: 51

Date Format when editing asp.net mvc

I'm facing a problem with the format of the Date when editing. That is my validation parameter:

[Required]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime dateIn

When entering the date in database (create) the format for ex: 22/02/1998 is correct but when editing, the format it is 22.02.1998.

Even if there is the parameter AppyFormatInEditMode. It seems that it doesn't work.

Upvotes: 0

Views: 173

Answers (1)

Soner Gönül
Soner Gönül

Reputation: 98740

Well, I feel like your CurrentCulture's DateSeparator is . and / replace itself to it

From DisplayFormatAttribute.DataFormatString property

Use the DataFormatString property to specify a custom display format for the values that are displayed in the DynamicField object.

And from "/" Custom Format Specifier

The "/" custom format specifier represents the date separator, which is used to differentiate years, months, and days. The appropriate localized date separator is retrieved from the DateTimeFormatInfo.DateSeparator property of the current or specified culture.

You can try to escape your / character like

[DisplayFormat(DataFormatString = "{0:dd\/MM\/yyyy}",...

Upvotes: 1

Related Questions