Reputation: 17024
I have the following properties in my View Model:
public decimal Credit { get; set; }
[EmailAddress]
public string TestEmail { get; set; }
And I got these 2 error messages on Serverside validation, using @Html.ValidationSummary()
:
The second one is perfect translated using the [EmailAddress]
Attribute. However the first one, is still in english. Why?
I have googled a bit but every solution is talking about customizing the Validation-messages. What I want is the default Validation-message, but translated to my Culture, like the [EmailAddress]
Attribute.
I have this in my web.config:
<system.web>
<globalization culture="de-DE" uiCulture="de-DE"/>
So how can I make the message The value '97,50 €' is not valid for Credit. be translated to another language?
I have not included the client side validation scripts.
Upvotes: 1
Views: 397
Reputation: 5730
Create a Messages.resx
in the folder App_GlobalResources
.
Add the following line:
PropertyValueInvalid | Der Wert "{0}" ist für das Feld "{1}" nicht erlaubt.
Then point to the Messages.resx
in you Application_Start()
ClientDataTypeModelValidatorProvider.ResourceClassKey = "Messages";
DefaultModelBinder.ResourceClassKey = "Messages";
Some others which might be helpfull:
FieldMustBeDate | Das Feld "{0}" ist kein gültiges Datum.
FieldMustBeNumeric | Das Feld "{0}" ist keine gültige Zahl.
PropertyValueRequired | Das Feld "{0}" ist erforderlich.
Upvotes: 1