Simply add a property to your view model:
public string FirstName { get; set; }
public string FirstLetterOfName
{
get
{
// TODO: a minimum amount of error checking
// might be good here for cases when FirstName
// is null or an empty string
return this.FirstName.Substring(1, 1);
}
}
and then:
@Html.DisplayFor(modelItem => item.FirstLetterOfName)
And if you now tell me that you are not using view models but are directly passing your domain entities to your views (which is very bad design), you might use a custom template:
@Html.DisplayFor(modelItem => item.FirstName, "FirstLetter")
and then you define a custom display template ~/Views/Shared/DisplayTemplates/FirstLetter.cshtml
with the following contents:
@ViewData.TemplateInfo.FormattedModelValue.Substring(1, 1)