如何将编码标签呈现为正确的HTML,而不是文本? [英] How to render encoded tags as proper HTML, rather than text?
问题描述
我从数据库获取以下文本:(由客户提供,所以我不能做太多)
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 - /><
- 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.<BR /><BR /> blah blah blah";
String Output = Server.HtmlDecode(Input);
这篇关于如何将编码标签呈现为正确的HTML,而不是文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!