Sometimes, in a Razor view, I am doing something similar to the following:
@Model.SomeDate1.ToString("MM/dd/yyyy")
This works sometimes, and sometimes it gives me an error about no overload for ToString takes 1 arguments. The answers I've found are similar to what's found here: 'No overload for method 'ToString' takes '1' arguments' error occur While Formatting Datetime Field To String ON "dd-MM-yyyy" format
I know when this error occurs, I can always modify my statement to
@Model.SomeDate2.Value.ToString("MM/dd/yyyy")
and it will work. My question is, why does this happen under these circumstances? These properties are brought through with the same type (non nullable DateTime) at the same time, on the same object, populated from the same table in the same database. Just one requires .Value
before the .ToString()
and the other doesn't. Why is this?