简体   繁体   English

更改ModelState.ModelError中的编码

[英]Change Encoding in ModelState.ModelError

Here is my problem: I add a message to ModelError with addModelError(String.Empty,”My message”) . 这是我的问题:我使用addModelError(String.Empty,”My message”)向ModelError添加消息。 In my view I just call @Html.ValidationSummary(). 在我看来,我只是调用@Html.ValidationSummary(). The message is in German and the characters Ö, Ä, Ü are just shown as questionmark. 该消息以德语显示,字符Ö,Ä,Ü仅显示为问号。 How do I change that? 我该如何改变?

As I see it there are two options. 在我看来,有两种选择。 One option is to write a custom validation summary helper which doesn't HTML encode the messages like described in the link that Kartikeya Khosla provided. 一种选择是编写自定义验证摘要帮助程序,该帮助程序不对消息进行HTML编码,如Kartikeya Khosla提供的链接中所述。 Or, and that's what I did, Just use the Unicode reference in the message string. 或者,这就是我所做的,只需在消息字符串中使用Unicode参考即可。 The solution in Kartikeya is more elegant, but in my case it is a lot of code to change two characters. Kartikeya中的解决方案更为优雅,但就我而言,更改两个字符的代码很多。 By the way here a link to look them up if anybody wants to do the same: 顺便说一下,如果有人想做同样的事情,这里有一个链接来查找它们:

http://www.utf8-chartable.de/unicode-utf8-table.pl?utf8=oct&unicodeinhtml=dec&htmlent=1 http://www.utf8-chartable.de/unicode-utf8-table.pl?utf8=oct&unicodeinhtml=dec&htmlent=1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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