字符串错误文本编码发送到的JavaScript [英] Wrong text encoding in string sent to javascript

查看:73
本文介绍了字符串错误文本编码发送到的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 (æ&#248 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆