如何将编码的标签呈现为正确的 HTML,而不是文本? [英] How to render encoded tags as proper HTML, rather than text?

查看:20
本文介绍了如何将编码的标签呈现为正确的 HTML,而不是文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从数据库中获取以下文本:(由客户提供,所以我不能用它做太多事情)

I'm getting the following text from a database: (supplied by client, so I can't do much with it)

investment professionals.<BR /><BR /> blah blah blah

呈现为:

investment professionals.<BR /><BR /> blah blah blah

我不想在屏幕上打印 <BR/> 标签.我希望他们表现得像真正的休息时间.

I don't want to print the <BR /> tags on the screen. I want them to behave as actual breaks.

以下 Html Helper 代码构建它所在的跨度,将其添加到 div 并返回 HTML 字符串:

The following Html Helper code builds the span it exists in, adds that to a div and returns the HTML string:

StringBuilder sbElements = new StringBuilder();

TagBuilder span = new TagBuilder("span") {InnerHtml = subject.AboutText};
sbElements.Append(span.ToString());

TagBuilder div = new TagBuilder("div");
div.MergeAttribute("class", "about-text");
div.InnerHtml = sbElements.ToString();

return div.ToString();

如果我 Html.Encode() 辅助方法的输出,编码的标签 - /&gt;&lt; - 被写入屏幕.如何获取我拥有的源文本并确保标签呈现为 HTML,而不是文本?

If I Html.Encode() the output of the helper method, the encoded tags - /&gt;&lt; - get written to the screen. How can I take the source text I have and ensure that the tags get rendered as HTML, rather than text?

推荐答案

试试这个:

    String Input = "investment professionals.&lt;BR /&gt;&lt;BR /&gt; blah blah blah";

    String Output = Server.HtmlDecode(Input);

这篇关于如何将编码的标签呈现为正确的 HTML,而不是文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆