Validation issue with Windows Azure, EF, and MVC3

I have a validation error issue that only appears on Windows Azure, but not on the local Azure emulator.

In my model, I have a class with the Start attribute and DisplayFormat for the German date format:

[Required] [DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}", ApplyFormatInEditMode = true)] [Display(Name = "Beginn")] public DateTime Start { get; set; } 

Everything is fine on my local machine, but when I try to save the field in a Windows Azure instance, I get this validation message:

The value "08/22/2011" is not valid for Beginn.

Both (local and cloud) using the same database (Azure SQL). So, I'm confused. Any idea how to fix this?

+6
source share
1 answer

The DisplayFormat attribute (as its name suggests) is used only to display the property value using the specified format. This has nothing to do with verification.

In this case, the check is performed using the default binder when it tries to set the POSTed string to the DateTime property. It uses a standard locale, which can be specified in your web.config using the globalization element:

 <system.web> ... <globalization culture="de-DE" uiCulture="de-DE"/> </system.web> 

The reason your code doesn’t work when deployed to an Azure instance is because it is likely that the server is configured to use an en-US culture for which the date format is different.

If you want to use some more specific format, you can also write your own model linking device for your viewing model and manually analyze the POSTED value inside using this special custom format.

+7
source

Source: https://habr.com/ru/post/895498/


All Articles