문제

when the date property is set in the model, this is executed:

if (!(rdr["JobEnded"] is DBNull)) { job.JobEnded = (DateTime)rdr["JobEnded"]; }

which results in job.JobEnded being 1/1/0001 12:00:00 AM.

What can I use in place of

@Html.DisplayFor(modelItem => item.JobEnded)

to show "In Progress" instead of "1/1/0001 12:00:00 AM".

I've tried putting an if/else in the view, but was only able to display a valid date or nothing. I'm sure I'm missing something really basic here as this is my first attempt at an APS.NET MVC view.

도움이 되었습니까?

해결책

You're dealing with default dates here, so to test for it, you need to use:

@if (item.JobEnded == default(DateTime))
{
    @:In Progress
}
else
{
    @Html.DisplayFor(m => item.JobEnded)
}

Or in one-liner form:

@((item.JobEnded == default(DateTime)) ? "In Progress" : Html.DisplayFor(m => item.JobEnded).ToString())
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top