Basically, I have a custom built EndDate Date class in my MVC output model. FYI: The Date class builds a DateTime, but hides the functionality of time. I created a display template for this type of date that formats the date nicely, but in the instance instance (shown below), if the object is null (in this case for EndDate), I would like to display the text βNo end dateβ instead.
<%:Html.DisplayFor(m => m.EndDate)%>
I cannot change the display template, which is common to all instances of the Date object, I also do not want to change the model itself. Basically, I want something like:
<%:Html.DisplayFor((m => (m.EndDate == null) ? "No End Date Specified" : m.EndDate)%>
Is this possible in any form? If not, what will be the best way to implement this functionality. I think, even if there is a way to do this, if it is not a good idea, please let me know why not and any better way to do it.
source
share