views:

183

answers:

2

I am storing pieces of XHTML as text on a search index. Once the user submits a search request, I insert this text in my page and return it to the server. This all works fine except when there is a ISO 8859-1 Symbol in the text (such as a copyright symbol ©). The symbol is not represented correctly in the browser, it is displayed as the entity number (© for the copyright symbol ©) and is not displayed as the symbol.

If I copy and paste the XHTML into a static web page and look at it in the browser, the symbol is rendered correctly.

When I do view source, I see the same text string under both conditions mentioned above.

Can you please tell me what is going on, and how do I fix it.

I am using ASP.NET MVC 2 and using the following code to add the XHTML inside an .ascx page where my Model is a collection o strings, each holding a piece of XHTML:

<%foreach(string s in ViewData.Model)  {%>
  <%= s %>
  <%} %>   
<%

Thanks for your help!

CoderGeek

+1  A: 

You need to html encode the strings in order to render them correctly:

<%= Html.Encode(s) %>

or if you are using ASP.NET 4 you may take advantage of the new code nugget shortcut:

<%: s %>
Darin Dimitrov
Thanks but that is not what I am trying to do. I want to render html, not render the text representation of html. My html renders fine except for these special characters.
A: 
minus4
lol shoould be (as one string but what do ya know its html encoded lol
minus4
Thanks!To get the browser to display © instead of © type the following without the space:#169;There is no input to html encode. All of this comes from my server. And all displays correctly, (the xhtml is rendered properly -- ie, the html elements are rendered), except for the symbols.Thanks!