stitch7c0 stitch7c0 - 21 days ago 4
Javascript Question

Showing text from resources.resx in JavaScript

This is example code in ASP.NET MVC 3 Razor:

@section header
<script type="text/javascript">
$(function() {


The code above this is just an example, but it also shows my problem with encoding. This variable @Resources.ExampleCompany is a file resources.resx with value
ExampleCompany = "Twoja firma / Twój biznes"

In JavaScript, the alert shows the "
Twoja firma / Tw&#243;j biznes

Why is character 'ó' '&#243'? What am I doing wrong?

In HTML tag,
is displayed correctly.


Mark Schultheiss wrote a good hint and my "ugly solution" is:

var companySample = "@Resources.ExampleCompany";

Now the character is
and looks good, but this is still not answer to my issue.


According to HTML Encoding Strings - Web Forms VS Razor View Engines, the @ syntax automatically HTML encodes and the solution is to use the Raw extension-method (e.g., @Html.Raw(Resources.ExampleCompany)) to decode the HTML. Try that and let us know if that works.