Unable to update date field when change the Application language (LanguageAbbrevation). "The value '20/06/2020' is not valid for Date Available"

Viewed 53

I am using dual language for my web application. "en" and "my". I implement this using resources. I have 2 resources files (WebResources.resx and WebResources.my.resx).

I encounter error when I try to update my view which contains a date field. The error is

"The value '20/06/2020' is not valid for Date Available"

which shows in the view after I click update. This happens when Im using the "en" language in the Application. But when I change it to "my" language, I can update the date.

The field in Model

[Display(Name =  "Date Available")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public Nullable<DateTime> AVAILABLE_DATE { get; set; }
    

The field in View

@Html.TextBoxFor(m => m.AVAILABLE_DATE, @"{0:dd\/MM\/yyyy}", new { @class = "form-control"})
@Html.ValidationMessageFor(model => model.AVAILABLE_DATE)

I suspect it has something to do with the Language/Culture. Any Idea?

Here is a sample you can check. Just click on Language to change the language, then go to Edit page and try to save. Link Here

1 Answers

My walkaround for this is I created another resource file named WebResources.en-GB.resx . I figured GB is using the same date format as MY.

Related