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) +"...";
}
}
精彩评论