ASP: NET MVC 5 - Localize Data Validation Message

I'm working on ASP.NET MVC 5. I am using attributes to validate my models. In the back-end combined with EF 6 and in the frontend combined with jQuery validation (just like in MVC samples and templates). A lot of my models have some int properties (they usually have a range attribute to test for them). Inside my shaving pages, I use standard HTML helper methods to create input elements for my models. If I create a textbox for the int property, ASP adds some jQuery validation attributes to the element (each attribute is localized expecting data-val-number).

Here's an example:

Model:

[Range( 1, 1000, ErrorMessageResourceType = typeof (Resources), ErrorMessageResourceName = "ValidationError_Range_propertyName_min_max" )]
[Required( ErrorMessageResourceType = typeof (Resources), ErrorMessageResourceName = "ValidationError_Required_propertyName" )]
public Int32 Number { get; set; }

      

HTML:

<input data-val="true" data-val-number="The field Nummer must be a number." data-val-range="Nummer muss zwischen 1 und 1000 sein." 
data-val-range-max="1000" data-val-range-min="1" data-val-required="Nummer ist erforderlich." id="Number" name="Card.Number" placeholder="Nummer" type="text" 
value="" aria-required="true" aria-invalid="true" class="input-validation-error" aria-describedby="Number-error">

      

How can I localize the data-val-number attribute?

Btw. Searching for this issue only returns answers on ASP.Net MVC 3 and 4. Hopefully there is a good solution in MVC 5.

+3


source to share





All Articles