MVC Razor need to get Substring

前端 未结 8 600
栀梦
栀梦 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条回答
  •  萌比男神i
    2020-12-19 00:04

    If you are only wanting to display the first character of item.FirstName why not do:

    @Html.DisplayFor(modelItem => item.FirstName.Substring(1,1))
    

    You have it the wrong side of the closing bracket.

提交回复
热议问题