MVC Razor need to get Substring

前端 未结 8 609
栀梦
栀梦 2020-12-18 23:24

I have the following inside of my view

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

I need to get the first initial of the First N

8条回答
  •  半阙折子戏
    2020-12-19 00:05

    This worked for me (no helper):

    @item.Description.ToString().Substring(0, (item.Description.Length > 10) ? 10 : item.Description.Length )
    

提交回复
热议问题