If you output a string in ASP.Net MVC using @ (Razor) or <%: %> (aspx), the string will automatically get HTML-encoded.
So if you reference a resource string (.resx) in Javascript,
<script type="text/javascript"> var x = "@resx.StringId"; </script>
AND the string contains characters the HTML-encoded (such as “&” => “&”, umlauts, accented characters, etc.), you’ll end up with a lot of ampersands.
The way I solved this problem in a recent project was to define an HtmlHelper extension like this:
public static IHtmlString JsString<TModel>(this HtmlHelper<TModel> html, string s) { Â return html.Raw(HttpUtility.JavaScriptStringEncode(s)); }
The string is first Javascript-encoded, and then written to the response stream unchanged using HtmlHelper.Raw().