渲染HTML和preserve空格和换行的字符串 [英] Render a string in HTML and preserve spaces and newlines

查看:209
本文介绍了渲染HTML和preserve空格和换行的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有了一个详细信息页的MVC3应用程序。由于这部分我有一个描述(从数据库中检索),有空间和新线路。当它在呈现新的线和空间由HTML忽略。我想带code的空间和新的生产线,使它们不会被忽略。

你是怎么做到的?

我试过HTML.En code,但它结束了显示的编码(甚至不是在空间和新的生产线,但在其他一些特殊字符)


解决方案

只是风格的内容空白:pre-包装;

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)

解决方案

Just style the content with white-space: pre-wrap;.

Working fiddle

这篇关于渲染HTML和preserve空格和换行的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆