Reputation: 426
on my dev pc the message are shown correctly in dutch. but on the server, all the validaton messages are english ???
to be sure the current culture is 'forced' correctly, i've placed this in my controller:
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("nl-BE")
to check which culture is active, i've placed this in my view:
<div>Culture: @Threading.Thread.CurrentThread.CurrentCulture</div>
my model has following fields:
<Required(ErrorMessage:="BlaBla {0}")>
<StringLength(1)>
Public Property Verkoper As String
<Required()>
<StringLength(1)>
Public Property Herkomst As String
the following is shown in the browser (after submitting an empty form, thus having validation errors for the 'required' attribute.)
on localhost:
Culture: nl-BE
BlaBla Verkoper
Het veld Herkomst is vereist.
this is the correct behaviour. culture is nl-BE and validation messages are dutch. a special errormessage is used for the 'Verkoper' field, as defined via the data-annotations. the error message for the 'herkomst' field is shown in dutch, as wanted.
on server:
Culture: nl-BE
BlaBla Verkoper
The Herkomst field is required.
this is NOT correct. the field 'Verkoper' with data-annotations is shown correctly, but the error message for the 'herkomst' field is shown in english?
what's wrong? can i have the correct validation messages on the server also?
Upvotes: 3
Views: 399
Reputation: 1223
You can direct set the Thread culture on the server, like this:
CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture("nl-BE");
Thread.CurrentThread.CurrentUICulture = cultureInfo;
Thread.CurrentThread.CurrentCulture = cultureInfo;
Upvotes: 0