使HTML识别\\\<br/>和\t [英] Getting HTML to recognize \n and \t
问题描述
我使用ASP.NET MVC3创建了一个Web应用程序,并且希望在视图中显示一个字符串(我在构造函数中构造的)。该字符串中包含\ n和\ t字符,并且我希望该格式保留在视图中。
I have created a web application using ASP.NET MVC3, and want to display a string (that I constructed in the constructor) in a view. This string has \n and \t characters in it, and I want that formatting to remain in the view.
截至目前,视图显示字符串没有任何格式化,就好像\\\
和\ t字符从来没有。我通过将它发送到System.Diagnostics.Debug.Write来检查我的字符串,并在输出中根据需要显示字符串。
As of now, the view displays the string without any of the formatting, as if the \n and \t characters were never there. I checked my string by sending it to System.Diagnostics.Debug.Write, and in the output, the string appears as desired.
在视图中,我正在写字符串
In the view, I am writing the string with
<p>@ViewBag.listItems</p>
(其中listItems是提到的字符串)。
那么,有没有人知道如何强制视图以所需的格式显示字符串?
字符串看起来像这样:
(where listItems is the string mentioned). So, does anyone know how to force the view to display the string in the desired format? The string looks something like this:
"Title 1 + \n\t + subtitle1 + \n\t + subtitle2 + \n\t + \n + Title2 + \n\t + subtitle1"
谢谢!
推荐答案
代替p标签,尝试使用pre。此元素中的任何文本都会保留格式,例如换行符等。
Instead of the "p" tag, try using "pre". Any text in this element will retain formatting such as line breaks, etc.
<pre>@ViewBag.listItems</pre>
这篇关于使HTML识别\\\<br/>和\t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!