开发者

Incorrect characters at ModelBinding

开发者 https://www.devze.com 2022-12-11 02:12 出处:网络
i have a problem i am developing an asp.net mvc project. Website is in Turkish Language. When i publish this website to IIS Turkish characters get crazy in web pages so i set globalization in my web.c

i have a problem i am developing an asp.net mvc project. Website is in Turkish Language. When i publish this website to IIS Turkish characters get crazy in web pages so i set globalization in my web.config as

<globalization fileEncoding="iso-8859-9" requestEncoding="iso-8859-9" responseEncoding="iso-8859-9"/>

After this Turkish characters shown correct.

But 开发者_高级运维now i have another problem when i enter Turkish text to an input text and then POST to my controller action, Turkish characters get crazy again.

I tracked the http messages Turkish text POST correctly ex: If i enter "Yücel" (ü is Turkish character) to input, i looked to HttpAnalyzer i can see that Post Data is "Yücel". When i look to my action's parameter's properties which are binded automatically by MVC, I see "Yücel".

Is there any suggestion from you to fix this problem?


I fixed the problem, what I did is,

  1. Delete following element from web.config so default encoding (UTF-8) will be used

    <globalization requestEncoding="utf-8" responseEncoding="utf-8"/>

  2. Delete following from my Site.Master

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9"/>


In web.config requestEncoding value;

<globalization requestEncoding="utf-8" ...

must be same as in web page charset value;

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

But you can also do other request enconding process by page address setting in web.config location tag setting. Sample:

<configuration>
...
<location path="path/to/your/actionmethod">
    <system.web>
        <globalization requestEncoding="ISO-8859-9" responseEncoding="ISO-8859-9" />
    </system.web>
</location>
...
</configuration>

http://www.siimviikman.com/2012/06/12/action-based-request-encoding-in-asp-net-mvc/

0

精彩评论

暂无评论...
验证码 换一张
取 消