Render a string in HTML and preserve spaces and li

2019-01-04 19:01发布

I have an MVC3 app that has a details page. As part of that I have a description (retrieved from a db) that has spaces and new lines. When it is rendered the new lines and spaces are ignored by the html. I would like to encode those spaces and new lines so that they aren't ignored.

How do you do that?

I tried HTML.Encode but it ended up displaying the encoding (and not even on the spaces and new lines but on some other special characters)

7条回答
Summer. ? 凉城
2楼-- · 2019-01-04 20:06

have you tried using <pre> tag.

http://jsfiddle.net/NweRa/

查看更多
登录 后发表回答