Share via

Does razor file support "Shift_JIS" encoding?

Xie Steven 831 Reputation points
2021-08-10T09:21:23.167+00:00

Hi,

The visual studio create the .cshtml file with UTF-8 encdoing. I save it ith "shift-jis" encoding by using 'Advanced save options..' in visual studio.

Now, it shows the Japanese words is displayed in garbled code.

            @Html.DisplayName("メニューを生成します。")  

I want to know if the razor engine support "shift-jis" encoding.

121951-1.jpg

Thanks

Developer technologies | ASP.NET Core | Other

Answer accepted by question author

Yiyi You - MSFT 521 Reputation points
2021-08-12T05:57:42.327+00:00

Hi,@Xie Steven ,

why not try to use UTF-8 in Advanced save options ?With UTF-8, the Japanese words can be shown correctly.
Here is my setting:
122889-image.png

result:
122900-image.png

----------

If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Best Regards,
YiyiYou

Was this answer helpful?


2 additional answers

Sort by: Most helpful
  1. cheong00 3,491 Reputation points Volunteer Moderator
    2021-08-10T14:57:26.233+00:00

    Razor do not limit the code page for any particular one, however you should check whether your master view contains something like the following:

    <meta charset="UTF-8" />  
    

    Also, there could be similar HTTP header specifying character set should be UTF-8 that you need to change if you need override.

    Note that these two change are site-wide changes. You may break other things if you do that. Always do full check after this kind of change to make sure things working okay.

    ======

    That said, since UTF-8 can represent all characters in Shift-JIS, do you have any particular reason to use it?

    Even if you need to support Shift-JIS data from database, you can always Encoding.Convert() your encoding in code before display/save it.

    Was this answer helpful?


  2. Bruce (SqlWork.com) 84,086 Reputation points
    2021-08-10T14:47:24.35+00:00

    Html has limited character set support. UTF-8, UTF-16, Windows-1252 and ISO-8859 only.

    You should use UTF-16 see

    https://learn.microsoft.com/en-us/dotnet/standard/base-types/character-encoding

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.