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 :
[Display(Name = "Last connection")]
[DisplayFormat(NullDisplayText = "Never connected")]
public DateTime? last_connection { get; set; }
then in your view :
@Html.DisplayFor(x => x.last_connection)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With