【发布时间】:2019-05-13 10:13:42
【问题描述】:
我有一些从 SQL 数据库中检索到的带有 HTML 标记的文本。如何使用 asp.net 在浏览器中显示没有 HTML 标记的相同文本?
【问题讨论】:
我有一些从 SQL 数据库中检索到的带有 HTML 标记的文本。如何使用 asp.net 在浏览器中显示没有 HTML 标记的相同文本?
【问题讨论】:
您可以使用@Html.Raw(Model.text)打印html
【讨论】:
我用form-view绑定数据库得到结果。
如果您存储了一些带有 HTML 标记的消息以在浏览器中查看,请使用:
project.aspx 页面
'<asp:FormView ID="fvhtml" runat="server" Width="100%">
<ItemTemplate>
<asp:Label ID="lblmsg" runat="server" Text="Message" Font-Size="25px"></asp:Label>
<asp:Label ID="lblhtml" runat="server" Text='<%# Bind("**`column name`**") %>' />
<br />
</ItemTemplate>
</asp:FormView>'
project.aspx.cs
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionstring name"].ToString());
//message binding start from here
try
{
con.Open();
SqlDataAdapter sqlda = new SqlDataAdapter("SELECT TOP 1 column name FROM table name", con);
DataTable dt = new DataTable();
sqlda.Fill(dt);
fvhtml.DataSource = dt;
fvhtml.DataBind();
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
con.Close();
}
【讨论】: