asp.net-mvcencodingmodelstateaddmodelerror

Change Encoding in ModelState.ModelError


Here is my problem: I add a message to ModelError with addModelError(String.Empty,”My message”). In my view I just call @Html.ValidationSummary(). The message is in German and the characters Ö, Ä, Ü are just shown as questionmark. How do I change that?


Solution

  • 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. Or, and that’s what I did, Just use the Unicode reference in the message string. The solution in Kartikeya is more elegant, but in my case it is a lot of code to change two characters. 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