Reputation: 23
The field DateOfBirth has the type DateTime
.
I want to apply method ToString()
in View:
@Html.DisplayFor(modelItem => Model.DateOfBirth).ToString("D")
But it doesn't work, because method ToString
has 0 parameters.
I resolved this problem. In model I have the second field:
public string DateOfBirth2
{
get { return DateOfBirth.ToString("D"); }
}
And then I use this field in View.
But I want to know, if I can use method ToString("D")
in View.
Upvotes: 0
Views: 387
Reputation: 887195
You should display the property directly, without using DisplayFor
:
@Model.DateOfBirth.ToString("D");
Upvotes: 1