I am trying to display the following in a view but is giving a problem:
<td>
@item.CreatedByDt.ToString("MM/dd/yyyy")
</td>
Any idea on how to handle a nullable Date field in a view. I am using Razor by the way.
I am getting the following error:
No overload for method 'ToString' takes 1 arguments
If you don't know if it will be null or not...
@string.Format("{0:MM/dd/yyyy}", item.CreatedByDt)
@(item.CreatedByDt.HasValue ? item.CreatedByDt.Value.ToString("MM/dd/yyyy") : "--/--/----")
You can replace the display string for when your date is null with what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With