ASP MVC Post 编码 Shift-Jis

ASP MVC Post Encoding Shift-Jis

我有一个位于普通 .html 文件中的表单,其中包含以下元标记:

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

我正在 post 填写表单的服务要求数据采用 shift-jis 编码。当我 post 通过使用 Chrome 打开这个 .html 文件,然后单击提交按钮时,服务可以正常接受它。当我检查 Fiddler 中的 post 值时,日语字符出现在服务的 post 中,如下所示:

goods_name_1 = "����i��P"

现在,当我采用完全相同的形式并将其放置在 ASP MVC 视图中时,将视图提供给 Chrome,其源与我在 .html 文件,查看源代码看起来与打开的 .html 版本完全一样。但问题是当我 post 带有提交按钮的表单时, post 值如下所示:

goods_name_1 = "商品1"

服务随后回复编码问题。

任何人都可以提出可能出了什么问题吗?从 ASP MVC 提供的视图具有响应 header "Content-Type:text/html; charset=utf-8"。我不确定为什么 post 值与 .HTML 文件版本不同。有什么想法吗?

补充一下,我的 .html 文件在 windows.

中保存为 Unicode

谢谢。

在您的控制器中设置响应的 ContentEncoding:

public ActionResult MyAction() {
    Response.ContentEncoding = System.Text.Encoding.GetEncoding("shift_jis");
    return View();
}

或在视图中:

@{
    ViewBag.Title = "Home Page";
    Response.ContentEncoding = System.Text.Encoding.GetEncoding("shift_jis");
}