gpt4 book ai didi

javascript - 在 Javascript 中使用时,服务器端代码会自动对字符进行编码

转载 作者:行者123 更新时间:2023-12-03 02:01:33 26 4
gpt4 key购买 nike

我有一个MVC应用程序,其中在页面加载时我使用从服务器接收到的模型值初始化javascript函数调用

类似这样的事情:

myFunction('@Model.ServerUnicodeCharacters');

现在,当我设置值

Model.ServerUnicodeCharacters = '科特迪瓦'

在 javascript 中我得到“C ô ;te d' ;Ivoire”

(故意在分号前添加空格以显示输出)

有没有办法跳过 ASP.NET MVC 中默认的字符编码?

最佳答案

尝试替换:

myFunction('@Model.ServerUnicodeCharacters');

与:

myFunction('@Html.Raw(Model.ServerUnicodeCharacters)');

摘自 MSDN:

The Razor syntax @ operator HTML-encodes text before rendering it to the HTTP response. This causes the text to be displayed as regular text in the web page instead of being interpreted as HTML markup.

MSDN Reference

关于javascript - 在 Javascript 中使用时,服务器端代码会自动对字符进行编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49995493/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com