使用ASP.NET MVC进行HTML.Encode本地化

时间:2022-10-28 16:38:57

How can I escape localized string encoding:

如何逃避本地化的字符串编码:

<%= Html.Encode("ÆØÅ") %> from rendering  &#198;&#216;&#197;

is there another way to encode localized strings?

有另一种方法来编码本地化的字符串?

1 个解决方案

#1


That's being encoded twice - are you using this in a HtmlHelper call?

那是两次编码 - 你在HtmlHelper调用中使用它吗?

// this will display&#198;&#216;&#197; as Html.TextBox encodes the
// value passed to it so it's encoded twice in this line
<%=Html.TextBox("sdfsdf", Html.Encode("ÆØÅ"))%><br />

// this will display ÆØÅ
<%= Html.Encode("ÆØÅ") %><br />

// As will this
<%=Html.TextBox("sdfsdf", "ÆØÅ")%><br />

#1


That's being encoded twice - are you using this in a HtmlHelper call?

那是两次编码 - 你在HtmlHelper调用中使用它吗?

// this will display&#198;&#216;&#197; as Html.TextBox encodes the
// value passed to it so it's encoded twice in this line
<%=Html.TextBox("sdfsdf", Html.Encode("ÆØÅ"))%><br />

// this will display ÆØÅ
<%= Html.Encode("ÆØÅ") %><br />

// As will this
<%=Html.TextBox("sdfsdf", "ÆØÅ")%><br />