Andrei
Andrei

Reputation: 44620

ASP.NET MVC validation message encoding issue

I have model with validation by data annotations:

public class MyModel 
{
    [Required(ErrorMessage = "Введите название")] //cyrillic (cap)
    public string Name { get; set; }
}

When I see this validation message in browser, it looks like that:

Îòïðàâë ïîâòîðíî

I have <meta http-equiv="content-type" content="text/html; charset=utf-8" /> in head.

How can I fix that?

Upvotes: 0

Views: 1203

Answers (3)

Aleksandr
Aleksandr

Reputation: 13

Andrei, I had the same problem. But your solution didn't work for me. I managed it only by saving cs-file in UTF-8. In earlier version of VS I had no problem with ErrorMessages in russian language.

Upvotes: 1

Andrei
Andrei

Reputation: 44620

Accidently I found how to fix it:

Project properties -> Application -> Assembly Information -> Neutral language

enter image description here

Upvotes: -1

Darin Dimitrov
Darin Dimitrov

Reputation: 1039160

Make sure that your Razor templates (.cshtml/.vbhtml) files are UTF-8 encoded: in Visual Studio open your _Layout.cshtml and select File -> Save As and then Save with Encoding...

enter image description here

Then select Unicode (UTF-8 with signature):

enter image description here

Do the same for all your Razor templates and views.

Also if you are using HTML 5 you might use the shorter version of the meta tag:

<meta charset="utf-8">

Upvotes: 2

Related Questions