How do I get my form submission to understand unicode characters?

When some users of my ASP.NET app enter the following text

Je bénéficie d'un coaching

I get the following value in my Request.Form:

Je b n ficie d un coaching

At first my page had the encoding set to Latin1, and I thought that changing it to Unicode (UTF8) using the following meta tag would help:

<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>

But after the change I still get those "blocks" in Request.Form.

Now the weird thing is, this happens when I submit the page which is being served by IIS (eg http://localhost/myform.aspx). If I get the same html, save it locally, open the file in the browser directly (eg c:myform.html) and submit it, all is fine, I see the unicode characters in my Request.Form as they should be.

Any tips? I am lost here...


The meta tag you mentioned ensures that the content of the page is rendered following the UTF-8 codepage, but doesn't inform how data posted should be handled. For that, you should add this attribute in your form tag:

<form accept-charset="utf-8" ....>

No idea why the behaviour is different when you run it through IIS and the file system, though.


You can try "charset=ISO-8859-1". I hope that help's.

链接地址: http://www.djcxy.com/p/60708.html

上一篇: 在剃刀视图引擎中逃离@角色

下一篇: 如何获取表单提交以了解unicode字符?