开发者

crop text to fit in column - html helper

开发者 https://www.devze.com 2023-03-12 04:31 出处:网络
Is there a html helper that can crop text (say, for an act开发者_JS百科ionlink) so that it fits into a table column without wrapping? I remember reading about a helper that crops and then adds ... to

Is there a html helper that can crop text (say, for an act开发者_JS百科ionlink) so that it fits into a table column without wrapping? I remember reading about a helper that crops and then adds ... to the end, but cannot find it again. Otherwise, I will just make my own helper.


No there isn't. There is an example of one in the ASP.NET MVC Music Store tutorials which is where you may have seen it.

Copied from the tutorial:

public static stringTruncate(this HtmlHelperhelper,string input,int length)
{ 
    if(input.Length <= length)
    { 
        returninput;
    } 
    else 
    { 
        returninput.Substring(0, length) +"...";
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号