8

The » character seems to get rendered as » in a razor view. I have tried

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

and

@Html.Raw()

but the problem does not go away. I did not have this issue with ASPX views.

Also, culture is set as

<globalization uiCulture="en" culture="en-US" />
sean
  • 11,164
  • 8
  • 48
  • 56
  • Check that your browser thinks it's encoded in UTF-8 and that the .cshtml file was saved in UTF-8 with signature (File / Advanced Save Options...). – Codo Jul 17 '12 at 05:46
  • Yup firefox pageinfo says utf-8 encoding. But saved with UTF-8 with signature fixed the problem. Originally saved as UTF-8 without signature. Thanks. BTW, how do you check if the browser thinks it is in UTF-8? – sean Jul 17 '12 at 06:05
  • In Firefox, it's Page Info. In IE, the context menu on the page has a Encoding submenu. – Codo Jul 17 '12 at 07:27

1 Answers1

18

I suspect that your .cshtml view/partial containing this character is not saved with the UTF-8 with signature encoding. Also do the same verification for the _Layout. In VS use the Save As with encoding dialog:

enter image description here

Also make sure that you have put the » character as-is in your view. Not coming from a string, XML or a database. If it comes from somewhere else make sure that it is not corrupted already when you are reading it. If this is the case please show the code that is retrieving the string that you are trying to output in the view.

Final remark about your meta tag: if you are using HTML5 use:

<meta charset="utf-8" />
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • do you know why this problem did not exist with ASPX views? – sean Jul 17 '12 at 06:17
  • This problem doesn't exist with Razor neither. Someone must have messed up with the encoding of your file. An external text editor or something and simply changed the encoding. – Darin Dimitrov Jul 17 '12 at 06:17
  • 2
    Yes, you're right. Just checked the old version of the file before I converted it over to MVC3 using a tool and it is in UTF-8 with BOM. – sean Jul 17 '12 at 06:20
  • 1
    In Visual Studio you need to save with encoding `UTF-8 with signature`, as shown above, but in other text-editors it's often shown as `UTF-8 with BOM` or `UTF-8 (with Byte Order Mark)`. This solved my problem in Sublime Text. – Phil Ricketts Nov 13 '12 at 20:31
  • Nice one. Razor was mangling currency symbols until I noticed the BOM was missing (Gulp removes it when copying files (src/dest). – Dave Clarke Nov 28 '17 at 14:11