stitch7c0 stitch7c0 - 1 year ago 99
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download