简体   繁体   中英

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?

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...

在此处输入图片说明

Then select Unicode (UTF-8 with signature):

在此处输入图片说明

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">

Accidently I found how to fix it:

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

在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM