Just a quick tip from my last post…
Notice how I didn’t check for nulls in the code sample:
@model DateTime?
@string.Format("{0:yyyy-MM-dd}", Model)
You’d think it would be necessary to do something like so instead:
@model DateTime?
@(Model.HasValue ? Model.Value.ToString("yyyy-MM-dd") : "")
However, String.Format in the .NET framework will just return an empty string when formatting null values. I thought this was handy, and it seems to pop up in a surprising number of cases.