I have a nullable datetime hat I get from the DB. currently I have my datetime? properties in my model and call them like this in the view to work properly.
<h6>@GTSConnectContent.DateOfLoading: <span>
@{
if (@consignmentDetails.DateOfLoading.HasValue)
{
@consignmentDetails.DateOfLoading.Value.ToShortDateString();
}
}
</span>
</h6>
But isn't there a way to set it in the actual model so it doesn't have to be set like this in the view. I tried the following but doesn't work
[DisplayFormat(DataFormatString = "yyyy/MM/dd")]
public DateTime? DateOfLoading { get; set; }