Reputation: 477
I'm stuck with ASP.NET MVC 3 jQuery unobtrusive validation message localisation. Specifically with "number" validation. If I have a number property in model input html is rendered with data-val-number attribute with value "The field Quantity must be a number." How I can localize this string. With data annotation attributes there is no problem to define localized message. But for number validation I do not have to specify any attribute.
So, how can be localized validation messages generated by unobtrusive validation?
Upvotes: 5
Views: 4107
Reputation: 10710
Found something. This blog explains step by step how to accomplish this. I just tried a quick run through using MVC 3 unobstructed validation and it worked perfect.
Basically, you add a resource, and use validation attribute like this:
[Range(1, 130, ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "Range")]
public string myNumber { get; set; }
The result was client validation with my custom string.
Upvotes: 0
Reputation: 477
I got to solution refering this article http://jwwishart.wordpress.com/2010/03/22/custom-server-and-client-side-required-validator-in-mvc-2-using-jquery-validate/
It works, but still very unconvenient.
If there is only one culture it could be convenient to use
$('input[data-val-number]').attr('data-val-number', 'Custom message');
This script must go before
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
Upvotes: 3