In my project, I use unobtrusive validation with adding attributes to the properties of the model class. There is a class:

public class Person { //some properties [RegularExpression("[a-zA-ZА-Яа-я]*")] public int LAST_NAME {get; set;} } 

Those. I assume that when validating on the client side, only Russian and English characters (uppercase and lowercase) will be allowed. If you enter the surname on the English layout, then everything works, but the validation of Russian letters does not work. At the same time, ValidationMessageFor-helper returns the following message:

 "The field LAST_NAME must match the regular expression '[à-ÿÀ-ß]*'." 

As far as I understand, the problem lies in the culture. If someone faced a similar problem, prompt the decision. Thank.

    1 answer 1

    The problem is not in culture, but in coding. Check the following locations:

    1. the encoding of the .cs file and whether it is the same as expected by the compiler. To do this, try in the debugger in the Watches window ("Control Values") type typeof(Person).GetProperty("LAST_NAME").GetCustomAttributes() and see what is typeof(Person).GetProperty("LAST_NAME").GetCustomAttributes() there.

    2. source page coding and whether the web server understands it. It does not directly affect the problem - but checking it out will avoid double (masked) errors. Write somewhere on the page something like @{ var q = "Привет, мир!"; } @{ var q = "Привет, мир!"; } and look in the debugger what this variable is equal to.

    3. the coding of the web page and whether its browser understands. Do you even have Russian letters on the page?

    • In the Value column of the "Watch" window, I get "This expression creates the side effects". Russian letters are present. Client page encoding is UTF-8. - klutch1991
    • @ klutch1991 there should be a button that will start the expression to be calculated. - Pavel Mayorov
    • Returns {object [0x00000000]}. - klutch1991
    • @ klutch1991 do not believe. There should be an array of one element. - Pavel Mayorov
    • but it is. The GetCustomAttributes (false) method returns object [0x00000000]. - klutch1991