razor view » character rendered as »

2019-06-23 23:14发布

问题:

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" />

回答1:

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:

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" />