显示Html字符串

Cha*_*amp 2 html c# asp.net

我是C#的新手,我希望将html字符串(从ckEditor保存在数据库中)显示为html的页面

<div class="descriptionText">
 <% 
     Response.Write(dynamicHtml);
 %>
</div>
Run Code Online (Sandbox Code Playgroud)

它显示为:

<p> test &nbsp;ht<u>ml test </u>html<strong> test html&nbsp;</strong></p>
Run Code Online (Sandbox Code Playgroud)

但应该是:

测试html测试html 测试html 

注意:请建议我可以做Response.Write字符串的解决方案

Tho*_*and 5

试试这个:

<div class="descriptionText">
 <asp:Literal runat="server" id="lit"/>
</div>
Run Code Online (Sandbox Code Playgroud)

在您的代码隐藏中,将HTML绑定到文字:

lit.Text = dynamicHtml;
Run Code Online (Sandbox Code Playgroud)

我假设你通过一些查询从数据库中获取HTML文本,你基本上必须将结果绑定到文字.

更新:这似乎对我有用:

在您的ASPX页面中:

 <%= dynamicHtml %>
Run Code Online (Sandbox Code Playgroud)

在你的代码背后:

protected string dynamicHtml { get; set; }
Run Code Online (Sandbox Code Playgroud)

页面加载:

 dynamicHtml = "your HTML";
Run Code Online (Sandbox Code Playgroud)