I have the following inside of my view
@Html.DisplayFor(modelItem => item.FirstName)
I need to get the first initial of the First N
Two things I learned while trying to solve this problem which are key:
My solution was the following:
string test = item.FirstName.ToString();
string test_add = ""; //creating an empty variable
if(test.Length == 0) //situation where we have an empty instance
{
test_add = "0"; //or whatever you'd like it to be when item.FirstName is empty
}
else
{
test_add = test.Substring(0, 1);
}
and you can use @test_add in your razor code in place of @item.FirstName