4

I use jquery validate unobtrusive in the Asp.Net MVC 5 project. And validation works in English, but I want it in other language, Norwegian for instance.

I found messages_no.js here https://github.com/jzaefferer/jquery-validation/tree/master/src/localization and included that js file after jquery.validate.js and jquery.validate.unobtrusive.js. I can see in developer tools that it is included in page properly but error messages are still in English.

Am I missing something?

2
  • are you using Html helpers to generate the form controls? Commented Jan 25, 2016 at 15:13
  • Yes, I am using Html helpers. Commented Jan 25, 2016 at 15:19

1 Answer 1

4

The error messsage are retrieved from html attributes(data-val-) of controls. Controls are generated server side (Html.EditorFor), using the DataAnnotations of the property.

So for example instead of

[Required(ErrorMessage = "Required")]
public string Email { get; set; }

you should use resources (.resx files)

[Required(ErrorMessageResourceType = typeof(Resource), ErrorMessageResourceName = "Required"]    
public string Email { get; set; }

Make sure Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture are set in the desired culture.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, it works! I have one more question. Is it possible to define that error message globally, so I don't have to specify it everywhere I need Required attribute.
you want every property on every viewmodel to be required?
I want to be able only to write [Requried] and that it automatically fetches it from Resources.Required. If it is possible...
To define that in only one place, like some global attribute override.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.