asp.net-mvc - ASP.NET MVC - 渲染重音字符
问题描述
在我看来,我在渲染法语、西班牙语等重音字符时遇到问题。
例如。而不是渲染Olá
它呈现为Olá
我确实尝试过@Html.Raw(myVariable)
。它确实奏效了。但是,在我的应用程序中使用它非常烦人。有没有办法或解决方案可以在我的应用程序中进行这项工作?
我试过这个
<globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8"/>
但这没有用。
解决方案
To prevent the need for using Html.Raw()
, you have these options:
Avoid storing HTML encoded text in your database;
Avoid putting HTML encoded text in variables/properties of type
string
;If all you have is HTML encoded text, then you can use type
MvcHtmlString
for your variables/properties, and then Razor will refrain from encoding:var myEncodedVariable = MvcHtmlString.Create(myVariable);
and then in Razor:
@myEncodedVariable
although I agree this is little more than using a different workaround at a different location.
推荐阅读
- ruby-on-rails - 如何在 Rails 服务器上连续监听 UDP 套接字
- python - 我不能让标签交互变化
- python - 如何在不单击展开按钮的情况下抓取页面的源代码?
- r - R - 通过循环更新列
- clojure - Clojure - 迭代惰性集合时出现 StackOverflowError
- dart - 如何在 Dart 中修复未定义的 File() 类及其方法?
- python - 需要帮助来理解一段 while 循环代码吗?
- python - 为什么 shell 输出到 stderr?
- reactjs - 将我的站点部署到 Github 页面后,URL 出现严重问题我不知道如何修复
- json - 如何修复'AttributeError:'dict'对象没有属性......'python断言中的错误