问题描述
我想在文本框中显示一些非英文字符。
i want to display some non english characters in a textbox.
我尝试使用
$("#txtSearch").val('<%:Html.Raw(ViewBag.my_search)%>')
应该显示2100 - KøbenhavnØ,但它显示2100 - KøbenhavnÃ''。
It should display '2100 - København Ø' but it is displaying '2100 - København Ø'.
我的控制器从cookie读取此值并在ViewBag中分配它。在控制器中有
my controller reading this value from cookie and assigning it in a ViewBag. In the controller i have
ViewBag.my_search = cookie.Value
// here it is assigning the right danish word but when it displays inside the input box, it just displays wrong.
任何想法如何解决这个问题
any idea how to solve this??
EDIT:
好,它在我的本地电脑上运行良好,但是当我将它托管到某些远程托管提供商时,不执行。
Well, it is working good in my local pc, but when I host it into some remote hosting provider, it does not perform good.
推荐答案
< meta http-equiv =Content-Typecontent = text / html; charset = utf-8/>
不是设置页面编码的好方法,因为它被真实的http头覆盖。因此,如果远程主机提供程序发送一个内容类型头,它将被忽略。
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
is not a good way to set your page's encoding because it is overriden by the real http header. So if the remote hosting provider is sending a content-type header, it will be ignored.
您的数据正确的utf-8,所以这是好的。所有你需要做的是设置content-type http头,以便浏览器将它读为utf-8,而不是windows-1252。
Your data is correctly utf-8, so that's good. All you need do is set the content-type http header, so that the browser will read it as utf-8 and not windows-1252.
您可以设置您的个人页面以发送标题:
You can set your individual page to send the header with:
<%@ Page RequestEncoding="utf-8" ResponseEncoding="utf-8" %>
或者您可以在Web.config中全局设置:
Or you can set it in Web.config globally:
<configuration>
<system.web>
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
</configuration>
这篇关于在文本框中显示非英文字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!