ASP MVC Post Encoding Shift-Jis

1.1k views Asked by At

I have a form that is sits in a plain .html file with the following meta tag:

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

The service I'm posting a form to requires that the data is in shift-jis encoding. When I post this form by just opening this .html file with Chrome, then clicking a submit button, the service accepts it fine. When I inspect the post values in Fiddler, the Japanese characters appear in the post to the service like follows:

goods_name_1 = "���i�P"

Now when I take the exact same form and place it in an ASP MVC view, serve the view to Chrome with its source identical to the one I have in the .html file, view source looks exactly the same as the .html version opened did. But the problem is when I post the form with a submit button, the post values look like this:

goods_name_1 = "商品1"

The service then replies with an encoding issue.

Can anyone suggest what might be going wrong? The view served from ASP MVC has the response header "Content-Type:text/html; charset=utf-8". Im not sure why the post values aren't the same as the .HTML file version though. Any ideas?

Just to add, the .html file I have is saved as Unicode in windows.

1

There are 1 answers

0
Paul Taylor On BEST ANSWER

Set the ContentEncoding of the response either in your Controller:

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

Or in the View:

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