簡體   English   中英

HTML.ActionLink不顯示新行

[英]Html.ActionLink does not display new lines

我有這個問題

string text = Html.Raw(immobileTmp.Localita + "\n" + immobileTmp.PrezzoVendita).ToString();
@Html.ActionLink(text, "DettaglioImmobile", "Immobili", new { id = immobileTmp.Id }, null)

但是然后在兩個字符串之間僅在<br />沒有換行。

然后我嘗試

string text = Html.Raw(HttpUtility.HtmlEncode(immobileTmp.Localita + "\n" + immobileTmp.PrezzoVendita).Replace("\n", "<br/>")).ToHtmlString();
@Html.ActionLink(text, "DettaglioImmobile", "Immobili", new { id = immobileTmp.Id }, null)

但沒有更好的運氣。 有任何想法嗎?

我猜您需要插入兩個</ br> ,您是否嘗試過?

更新

試試Environment.NewLine ,像這樣:

string text = Html.Raw(immobileTmp.Localita + Environment.NewLine + immobileTmp.PrezzoVendita).ToString();
@Html.ActionLink(text, "DettaglioImmobile", "Immobili", new { id = immobileTmp.Id }, null)

嘗試這個:

String s1 = (immobileTmp.Localita).ToString() + " ";
String s2 = (immobileTmp.PrezzoVendita).ToString();
String s = s1 + s2

StringBuilder sb = new StringBuilder(s);

int i = 0;
while ((i = sb.indexOf(" ", i + s1.Length)) != -1) {
    sb.replace(i, i + 1, "\n");
}

string text = Html.Raw(s);

如果使用Environment.NewLine將字符串連接在一起,並將標簽包裝在<pre> ,則可以根據需要拆分行,如以下示例所示:

@{
    string sep = Environment.NewLine;
    string text = Html.Raw(immobileTmp.Localita + sep + immobileTmp.PrezzoVendita).ToString();
}

<pre>
    @Html.ActionLink(text, "DettaglioImmobile", "Immobili", new { id = immobileTmp.Id }, null)
</pre>

陷阱:文本將被設置為等距格式(因為<pre> ),但是CSS可以解決該問題( <pre class="blah">... )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM