Let's see an example: there is a German word: Fußgängerübergänge
What I have:
web.config file:
...
<system.web>
    <globalization
        fileEncoding="utf-8"
        requestEncoding="utf-8"
        responseEncoding="utf-8"
        culture="auto"
        uiCulture="auto"
    />
...
a resource file containing this word:
<?xml version="1.0" encoding="utf-8"?>
<root>
    ...
    <data name="TestWord" xml:space="preserve">
        <value>Fußgängerübergänge</value>       
    </data>
    ...
</root>
an html page hardcoded the same word and using this resource to reference this word and also retrieving this word from DB:
...
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    ...
</head>
<body>
    <div>Fußgängerübergänge</div>
    <div>@Model.SameWordFromDbTable.TestWord</div>
    <div>@Resources.MyResource.TestWord</div>
    <div>@MvcHtmlString.Create(Resources.MyResource.TestWord)</div>
</body>
...
When I check them in the source code of the webpage they appear in two different ways:
...
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    ...
</head>
<body>
    <div>Fußgängerübergänge</div>
    <div>Fußgängerübergänge</div>
    <div>Fußgängerübergänge</div>
    <div>Fußgängerübergänge</div>
</body>
...
Question: what did I do wrong, how can I fix this "encoding" issue? What should I do if a want the last 2 words appear in the source code as same as the first two?
If you want to prevent your text from being HTML encoded, you can simply use Html.Raw:
@Html.Raw(Resources.MyResource.TestWord)
Is the encoding actually a problem, though?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With