简体   繁体   English

限制显示的字符数

[英]Limit the number of characters displayed

How do i limit the number of characters diplayed. 我如何限制显示的字符数。

Here is my code from my cshtml file 这是我的cshtml文件中的代码

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

All Help Appreciated 感谢所有帮助

You can write a helper method like this in the Utility class and import in the Razor page or add in the web.config . 您可以在Utility类中编写这样的帮助程序方法,并在Razor页面中导入或在web.config中添加。 You can read here https://msdn.microsoft.com/en-in/library/bb383977.aspx 您可以在这里阅读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)); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM