字符串错误文本编码发送到的JavaScript [英] Wrong text encoding in string sent to javascript
问题描述
我有正在接收UTF-8 EN codeD字符串(ViewBag.errorText)JavaScript方法,并使用此作为参数传递给一个新的功能。
问题是,在 show_error_dialog
显示文本显示HTML转义字符(&放大器;#230;&放大器;#248
等),而不是预期的(æåø等)。
我presume问题是封闭<文本方式>
标签,但似乎无法来解决这个问题。
<脚本类型=文/ JavaScript的字符集=utf-8>
功能performLoadOperations(){
@if(ViewBag.errorText!= NULL){
<文字和GT; show_error_dialog('@ ViewBag.errorText');< /文字和GT;
}
}
< / SCRIPT>
我想所有剃刀插入的文本是HTML-CN $ C $默认光盘。使用 Html.Raw()
来传递字符串unen codeD。
<脚本类型=文/ JavaScript的字符集=utf-8>
功能performLoadOperations(){
@if(ViewBag.errorText!= NULL){
<文字和GT; show_error_dialog('@ Html.Raw(ViewBag.errorText)');< /文字和GT;
}
}
< / SCRIPT>
I have a javascript method which is receiving a UTF-8 encoded string (ViewBag.errorText), and uses this as a parameter to a new function.
The problem is that the text displayed in show_error_dialog
is displaying the html escaped characters (æø
etc') and not the intended ("æåø" etc.).
I presume the problem is the enclosed <text>
tags but can't seem to get around this.
<script type="text/javascript" charset="utf-8">
function performLoadOperations() {
@if(ViewBag.errorText!= null) {
<text>show_error_dialog('@ViewBag.errorText');</text>
}
}
</script>
I think all Razor-inserted text is HTML-encoded by default. Use Html.Raw()
to pass the string unencoded.
<script type="text/javascript" charset="utf-8">
function performLoadOperations() {
@if(ViewBag.errorText!= null) {
<text>show_error_dialog('@Html.Raw(ViewBag.errorText)');</text>
}
}
</script>
这篇关于字符串错误文本编码发送到的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!