我有一個字符串,我將其保存到數據庫。問題是,當我處於編輯模式表單時,它只顯示換行符。當我在我的網頁上顯示它(不編輯)或在電子郵件中使用它時,字符串顯示時沒有換行符,它們都一起運行(請參閱下面的圖片)。我使用MVC 4和VS2012。如何在網頁或電子郵件中正確顯示換行字符串
任何人都可以請告訴我如何獲得行飼料總是顯示?
string LF = " \r\n ";
//string LF = Environment.NewLine; // tried this also, did'nt work.
string appendComments = " ";
contact.Subject = "Quick Quote";
appendComments += "Make Sure to Contact Customer by: " + Request.Form["radio"].ToString(); ;
appendComments += LF + LF + "CARPET CLEANING: " + LF;
if ((Request.Form["bedRms"]) != "0") { appendComments += "Bedrooms =" + Request.Form["bedRms"] + ", " + LF; }
if ((Request.Form["familyRm"]) != "false" || (Request.Form["familyRm"]) == "on") { appendComments += "Family Room = Yes, " + LF; }
if ((Request.Form["livingRm"]) != "false" || (Request.Form["livingRm"]) == "on") { appendComments += "Living Room = Yes, " + LF; }
if ((Request.Form["diningRm"]) != "false" || (Request.Form["diningRm"]) == "on") { appendComments += "Dining Room = Yes, " + LF; }
if ((Request.Form["ld-combo"]) != "false" || (Request.Form["ld-combo"]) == "on") { appendComments += "Living/Dining Combo = Yes, " + LF; }
if ((Request.Form["pets"]) != "false" || (Request.Form["pets"]) == "on") { appendComments += "Pet Spot/Stain Issue = Yes " + LF; }
Here I save it to the database.
換行工作的編輯表單: works in edit form http://www.leadingedgewebsites.com/linefeedworks.jpg
換行不起作用時顯示其網頁上:
該字符串是用下面的代碼形式產生 Does Not Work on Webpage http://www.leadingedgewebsites.com/linefeednowork.jpg
換行不起作用於電子郵件: Does Not Work in email http://www.leadingedgewebsites.com/inemail.jpg
我很感激你花時間幫助我。
謝謝。
很遺憾,您必須根據目標格式將它們替換爲正確的_thing_。例如HTML(頁面和電子郵件)的
或RTF電子郵件的\ par(純文本電子郵件的\ n)。 –
使用'
'而不是'\ r \ n' –
您有一個XSS洞。 – SLaks