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
validation asp.net-mvc-5 data-annotations unobtrusive-validation


source to share


No one has answered this question yet

Check out similar questions:

2303
Checking decimal numbers in JavaScript - IsNumeric ()
1012
(Inline) way in JavaScript to check if a string is a valid number
839
Full regex to validate phone number
106
ASP.NET MVC Conditional Validation
five
ASP.NET MVC3 unobtrusive localization of jQuery validation messages
4
ASP.NET MVC ValidationAttribute causes invalid client side validation rules
3
Localization of asp.net mvc validation check messages for numbers (data-val-number)
2
ASP.Net MVC 3 - unobtrusive client side validation with DataAnnotations - field required but should not be
1
MVC.net data annotations not rendering for list items in view
0
jQuery SmartWizard with unobtrusive jQuery validation



All Articles
Loading...
X
Show
Funny
Dev
Pics