【发布时间】:2013-01-04 20:46:26
【问题描述】:
我有以下GetText() 函数,它与我的问题有关,在以下位置被调用:
myGridView.DataSource = stuff.Select(s => new
{
//...some stuff here
f.Text = GetText();
}
myGridView.DataBind();
GetText 如下所示:
private void string GetText()
{
StringBuilder sb = new StringBuilder();
sb.Append("<abbr title=\"Testing\">");
sp.Append("This is the Text that I want to display");
sb.Append("<\abbr>");
}
所以本质上,我想做的就是能够在我的网页上拥有以下 HTML:
<abbr title="Testing">This is the text that I want to display</abbr>
然而,出现了一个神秘的标签。在谷歌浏览器中,我查看了控制台,发现它看起来像这样:
<abbr title="Testing">This is the text that I want to display<bbr></abbr>
当我在sb.Append("<\abbr>"); 行中添加时生成了一个无关标签
当我删除该行时,此问题已修复,但我想找到更好的解决方案,因为这会使代码看起来很尴尬。
我也尝试执行以下操作,而不是多行的 sb.Appends(),但仍然显示额外的文本。
sb.Append(string.Format("<abbr title=\"testing\">{0}<\abbr>",Text));
注意:假设 Text 是一个字符串,它等于我要显示的文本。
【问题讨论】: