0

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.

1 Answer 1

1

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}",...
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer but it doesn't work when I try to escape / with backslah

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.