문제

I have a text that have som \n in it. But when showing the text in a div there are no line feeds.

How do I make a line feed in a div???

I have tried to Replace("\n","&lt;br /&gt;") and Replace("\n","&lt;p&gt;&lt;/p&gt;"). But the <br /> is showed instead of a line feed.

ASP.NET:

<div class="text"> <%: newsItem.Text %></div>

CSS:

.text
{
  color: Black;
  margin-top: 10px;
  margin-bottom: 10px;      
}
도움이 되었습니까?

해결책

Use:

<%= newsItem.Text %>

Instead of:

<%: newsItem.Text %>

The second method implicitly HTML encodes the string.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top