如果它比X字符更长,我如何格式化Razor CSHTML页面中的字符串:
<p>@Model.Council</p>
Example for an X = 9
-> if Council is "Lisbon", then the result is "<p>Lisbon</p>"
-> if Council is "Vila Real de Santo António", then the result is "<p>Vila Real...</p>" with the title over the <p> "Vila Real de Santo António" showing the complete information
谢谢.
解决方法:
任何字符串. See here.
而对于你的代码……
@(Model.Council.Length>10 ? Model.Council.Substring(0, 10)+"..." : Model.Council)