我有一些带有从SQL数据库检索的HTML标记的文本。如何使用asp.net在浏览器中显示没有HTML标记的相同文本?
答案 0 :(得分:0)
您可以使用@Html.Raw(Model.text)
打印html
答案 1 :(得分:0)
我使用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();
}