MVC Razor need to get Substring

前端 未结 8 606
栀梦
栀梦 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:01

    This will truncate at 10 characters and add "..." to the end if it is longer than 13 characters.

    @if (item.Notes.Length <= 13)
    {
      @Html.DisplayFor(modelItem => item.FirstName)
    }
    else
    {
      @(item.FirstName.ToString().Substring(0, 10) + "...")
    }
    

提交回复
热议问题