3

I'm posting JSON.stringify data to an MVC action and any UTF characters are coming through mangled despite setting the encoding in my javascript. Here's what my jQuery call looks like:

$.ajax({
    type: "POST",
    url: BaseAppPath + "/Controller/Action",
    dataType: "json",
    contentType: "application/json; charset=utf-8",
    data: JSON.stringify(jsonData),
    success: function (data) {
        // success code
    },
    error: function (xhr, textStatus, errorThrown) {
        // error code
    }
});

My action definition looks something like this:

public JsonResult ModifyTaskStatus(int taskId, string note)

I have a breakpoint on the first line of the action. At that time, the characters in the "note" parameter are hosed. Everything up until the breakpoint handles the characters properly. What do I need to do to ensure my action gets the chinese characters properly?

4

1 回答 1

1

首先想到的是您的 Web 应用程序可能没有设置为相同的编码。您的 web.config 中有元素吗?如果没有尝试添加到

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

当然还要确保您的页面在标签中设置了内容类型

<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
于 2012-06-08T19:06:46.280 回答