Rob177
Rob177

Reputation: 27

Limit the number of characters displayed

How do i limit the number of characters diplayed.

Here is my code from my cshtml file

@Html.DisplayFor(modelItem => item.Text) 

All Help Appreciated

Upvotes: 0

Views: 2701

Answers (1)

Devesh
Devesh

Reputation: 4550

You can write a helper method like this in the Utility class and import in the Razor page or add in the web.config . You can read here https://msdn.microsoft.com/en-in/library/bb383977.aspx

       public static string DisplayText(this string str , int charallowed){
            if(str.Length > charallowed)
                   return str.Substring(0,charallowed) + " ...." ;
            return str;
        }

        @Html.DisplayFor(modelItem => item.TextDisplayText(20)); 

Upvotes: 4

Related Questions