Nikita Ignatov
Nikita Ignatov

Reputation: 7163

HTML.Encode localization with ASP.NET MVC

How can I escape localized string encoding:

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

is there another way to encode localized strings?

Upvotes: 0

Views: 2999

Answers (1)

Steve Willcock
Steve Willcock

Reputation: 26839

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

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

Upvotes: 2

Related Questions