New to ASP.NET MVC 3. This seems like it should be a really simple issue, but it’s actually got me stumped. What I want to do is display a certain DateTime value if a value has been entered, or leave the space empty if no value has been entered. The code in my view is simply this:
<td>
@if (item.TimeReturned > DateTime.MinValue)
{
Html.DisplayFor(modelItem => item.TimeReturned);
}
</td>
which seems really basic and straightforward. Also, though it seems like overkill, TimeReturned explicitly defaults in the model to DateTime.MinValue.
No values are ever displayed. Just to make sure it wasn’t some operator funkiness, I also tried
<td>
@if (DateTime.Compare(item.TimeReturned,DateTime.MinValue) != 0)
{
Html.DisplayFor(modelItem => item.TimeReturned );
}
</td>
which also displays nothing. I must be missing some fundamental insight. I could write a method in the model class to accomplish this, I guess, but it seems intuitive to do it this way. Any guidance would be greatly appreciated!
Try,