.Replace(Environment.NewLine,&QUOT;&LT; BR /&GT;&QUOT;)的作品在本地主机上而不是当我上传我的网站主办 [英] .Replace(Environment.NewLine, "<br />") works on localhost but not when I upload my website to host
问题描述
我不知道这是为什么。这里是我的code和它完美的作品时,我尝试在本地主机上,但是当我上传我的网站我的文字没有&LT; BR /&GT;
的。为什么会发生这种情况?而如何解决新线这个问题? (空格:pre系列;
不是我一个解决方案,它不工作在IE6和它与我的风格搞乱)
@ Html.Raw(Html.En code(Model.Body)
.Replace(Environment.NewLine,&所述峰; br /&gt;中))≤峰; br /&GT;
由于BuildStarted在评论中提到的,浏览器可能或者发送 \\ r \\ n
或 \\ n
,这将打破,如果你使用 Environment.NewLine
- 我不认为asp.net会解决这个问题了前执行code。
我建议你使用一个普通的前pression,而不是取代换行:?\\\\ \\\\řN
这应该与这两种情况下(我不要指望任何浏览器实际只使用'\\ r')
I have no idea why is that. Here is my code and it works perfectly when I try it on localhost but when I upload my website my text has no <br />
's. Why this could happen? And how can I fix this issue with new lines? (white-space: pre-line;
is not a solution for me, it is not working on IE6 and it is messing with my styles)
@Html.Raw(Html.Encode(Model.Body)
.Replace(Environment.NewLine, "<br />"))<br />
As BuildStarted mentioned in the comments, the browsers might either send \r\n
or \n
, which will break, if you use Environment.NewLine
- and I don't think asp.net will fix that up before running your code.
I'd suggest you use a regular expression to replace linebreaks instead: "\\r?\\n"
This should match both cases (I don't expect any browser to actually use '\r' only).
这篇关于.Replace(Environment.NewLine,&QUOT;&LT; BR /&GT;&QUOT;)的作品在本地主机上而不是当我上传我的网站主办的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!