C# - 打印Html而不是字符串

时间:2013-07-17 17:01:41

标签: c# html printing html-encode

我在一个带有html标签的数据库中保存了一个字符串。我需要在我的网站上打印它,尊重这些样式(如斜体,粗体)。

问题是代替字符串格式化我得到带标签的字符串。

我用过:

<%=System.Net.WebUtility.HtmlEncode(dr_stream["Description"].ToString())%>

我第一次尝试没有HTML,也没用。

3 个答案:

答案 0 :(得分:0)

创建一个div并将div指定为myDiv.innerHtml = yourString

答案 1 :(得分:0)

我明白了。我在数据库上录制了编码版本。 我使用Decode而不是Encode,它起作用了。

答案 2 :(得分:0)

这可能是一个解决方案

ASP.NET MVC

@Html.Raw(dr_stream["Description"].ToString())

ASP.NET

<asp:Literal runat="server" Text='<%#dr_stream["Description"]%>'></asp:Literal>