在JavaScript中显示来自resources.resx的文本

sti*_*7c0 14 javascript encoding asp.net-mvc-3

这是ASP.NET MVC 3 Razor中的示例代码:

@section header
{
    <script type="text/javascript">    
        $(function() {
            alert('@Resources.ExampleCompany');
        });
    </script>
}

<div>
    <h1>@Resources.ExampleCompany</h1>
</div>
Run Code Online (Sandbox Code Playgroud)

上面的代码只是一个例子,但它也显示了我的编码问题.这个变量@ Resources.ExampleCompany是一个带有值的文件resources.resxExampleCompany = "Twoja firma / Twój biznes"

在JavaScript中,警报显示" Twoja firma / Tw&#243;j biznes".

为什么角色'ó''ó'?我究竟做错了什么?

在HTML标记中,<h1>@Resources.ExampleCompany</h1>正确显示.

更新:

Mark Schultheiss写了一个很好的提示,我的"丑陋的解决方案"是:

var companySample = "@Resources.ExampleCompany";
$('#temp').append(companySample);
alert($('#temp').text());
Run Code Online (Sandbox Code Playgroud)

现在角色&#243;看起来很好,但这仍然不能回答我的问题.

pet*_*ete 19

根据HTML Encoding Strings - ASP.NET Web Forms VS Razor View Engine,@语法自动HTML编码,解决方案是使用Raw扩展方法(例如@Html.Raw(Resources.ExampleCompany))来解码HTML.试试看,如果有效,请告诉我们.