How to configure mvc to support binding dd/MM/yyyy date formates for all cultures?

215 Views Asked by At

I have MVC web application and I am supporting 2 languages(Arabic, English).

I have post-action which takes the following model:

public class MyModel
{
    public DateTimeOffset StartDate { get; set; }
    public DateTimeOffset EndDate { get; set; }
}

When UI language is English it serializes the following date formate "dd/MM/yyyy" perfectly after adding globalization config inside web.config:

<globalization uiCulture="en" culture="en-GB" />

but when UI language is Arabic they are serialized into 0001-01-01T00:00:00 +00:00 (even the value posted by Jquery is startDate: 26/08/2020)

So how can I configure my web application to support binding the "dd/MM/yyyy" format for all cultures?

1

There are 1 best solutions below

0
Wowo Ot On

Try using this

[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}")]
public DateTimeOffset StartDate { get; set; }