开发者

show line breaks in output

开发者 https://www.devze.com 2023-02-10 06:31 出处:网络
when i enter text into a text area with linebreaks this is not being output later when i display the text. how do i let it show the line spaces?, instead all 开发者_开发问答the text is cramped togethe

when i enter text into a text area with linebreaks this is not being output later when i display the text. how do i let it show the line spaces?, instead all 开发者_开发问答the text is cramped together at the moment.


How do you display it? HTML ignores whitespace, including line breaks. You can replace the linebreaks with the <br> element to show the enters in your browser too.

Mind that any subsequent spaces are also ignored. You can use the <pre> element too, to display the exact text, but I think that long lines won't be wrapped in that case.


If you are putting your text into HTML try this just before writing it out to the page:

string myText = "" // your text
myText = myText.Replace(Environment.NewLine, "<br/>");


this worked:

MvcHtmlString.Create(Model.Post.Description.Replace(Environment.NewLine, "<br />"))
0

精彩评论

暂无评论...
验证码 换一张
取 消