System.InvalidCastException: Unable to cast object of type 'System.DateTime' to type 'System.String'
Hi,
I wondered if anybody could help me I am using Umbraco Cloud 11, and have a set of doc types to display a job vacancy like the below, What I would like is if the model value has data show the item, if not display none, the problem arises with the jobClosingDate item is null the whole page errors with this error:
Unable to cast object of type 'System.DateTime' to type 'System.String'
Any help would be much appreciated, thanks again to this great Umbraco community
check out this version where the cast is removed, it should check for null before you apply the ToString extension @Model.JobClosingDate?.ToString("dd") ::
System.InvalidCastException: Unable to cast object of type 'System.DateTime' to type 'System.String'
Hi,
I wondered if anybody could help me I am using Umbraco Cloud 11, and have a set of doc types to display a job vacancy like the below, What I would like is if the model value has data show the item, if not display none, the problem arises with the jobClosingDate item is null the whole page errors with this error:
Unable to cast object of type 'System.DateTime' to type 'System.String'
Any help would be much appreciated, thanks again to this great Umbraco community
Hi Nick, Looks like you're casting all your values before nullchecking:
check out this version where the cast is removed, it should check for null before you apply the ToString extension
@Model.JobClosingDate?.ToString("dd")
::hope this helps!
Many thanks Damien for your help, your solution worked perfectly,
Thanks again
is working on a reply...