display non english character in textbox

2019-08-22 01:24发布

i want to display some non english characters in a textbox.

i am trying with

$("#txtSearch").val('<%:Html.Raw(ViewBag.my_search)%>')

It should display '2100 - København Ø' but it is displaying '2100 - København Ø'.

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.

1条回答
爷、活的狠高调
2楼-- · 2019-08-22 02:00

<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.

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" %>

Or you can set it in Web.config globally:

<configuration>
  <system.web>
    <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
  </system.web>
</configuration>
查看更多
登录 后发表回答