c# – 如果word长于X,则用点替换字符串的结尾

如果它比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)
上一篇:MVC3 Razor:从视图中调用javascript函数


下一篇:c# – 如何在javascript脚本标记中使用剃刀for循环?