Is there a way to get an @Html.DisplayFor
value to show "NULL" in the view if the value of the model item is null
?
Here's an example of an item in my Details view that I'm working on currently. Right now if displays nothing if the value of the Description is null
.
<div class="display-field">
@Html.DisplayFor(model => model.Description)
</div>
yes, I would recommend using the following data annotation with a nullable datetime field in your codefirst model :
then in your view :
Display a string e.g. "-" in place of null values show via the "DisplayFor" standard helper using a helper extension, i.e. "DisplayForNull"
1. Create Folder "Helpers" and add a new controller "Helper.cs"
2. In your view
in place of
Hope it helps ;-)