1

我有一些文本存储在数据库中:

<p>Hi this is Roht <strong>Singh</strong></p>

当我检索它并将其 HTML 解码为标签控件时,它给了我以下文本:

<p>Hi this is Roht <strong>Singh</strong></p>

我的代码:

 label1.Text = Server.HtmlDecode(ds.Tables[0].Rows[0][0].ToString());

我怎样才能像这样将文本呈现为 HTML?

嗨,我是 Roht Singh

4

2 回答 2

4

看起来您的数据经过两次 HTML 编码。尝试解码两次:

label1.Text = Server.HtmlDecode(
                    Server.HtmlDecode(ds.Tables[0].Rows[0][0].ToString()
              );

当您获取原始数据时:

&amp;lt;p&amp;gt;Hi this is Roht &amp;lt;strong&amp;gt;Singh&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;

并对其进行 HTML 解码,您将得到以下信息:

&lt;p&gt;Hi this is Roht &lt;strong&gt;Singh&lt;/strong&gt;&lt;/p&gt;

当您对该结果进行 HTML 解码时,您会得到:

<p>Hi this is Roht <strong>Singh</strong></p>

然后应将其呈现为:

嗨,我是 Roht Singh

于 2013-07-25T03:38:39.177 回答
2

我已经解决了它我再次有 htmldecode 文本并且它正在工作。答:Server.HtmlDecode(Server.HtmlDecode(ds.Tables[0].Rows[0][0].ToString()));

于 2013-07-25T04:01:47.883 回答