开发者

crop text to fit in column - html helper

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜