0

I have an Asp.Net MVC 5 application which I am currently globalising.

In de-DE culture of the server my Date in the following format passes the serverside validation fine: dd.MM.yyyy

When I change the culture of the server to en-US the Display of the Date gets correctly converted to the MM/dd/yyyy date format. But when I click on send, server side validation fails.

result of validation

ModelState.IsValid is false and the date arrives in the controller as: {1/1/0001 12:00:00 AM}

This is my input field:

@Html.TextBoxFor(e => e.Date, Resource_Entries.DateFormat, new {@class = "form-control"})

This Resource_Entries.DateFormat is a value that is saved in a .resx file. In the en-US resx file this is saved there: {0:MM/dd/yyyy}

I use the TextBoxFor Helper because I use a bootstrap datepicker.

In my Model I have the following:

[Required(ErrorMessageResourceType = typeof(Error), ErrorMessageResourceName = "EntryEditViewModel_Date_Required")]
public System.DateTime Date { get; set; }

How can I fix this? I want the solution to work with de-DE culture aswell.

maracuja-juice
  • 994
  • 2
  • 14
  • 33

0 Answers0