asp.net-mvc – 在ASP.NET MVC DisplayFor Html Helper中为空值显示“NULL”

如果模型项目的值为空,有没有办法获取@ Html.displayFor值在视图中显示“NULL”?

以下是我在“细节”视图中正在处理的项目的示例。现在如果说明的值为空,则不显示任何内容

<div class="display-field">
    @Html.displayFor(model => model.Description)
</div>

解决方法

是的,我建议您在代码一个模型中使用以下数据注释和可空的datetime字段:
[display(Name = "Last connection")]
[displayFormat(NulldisplayText = "Never connected")]
public DateTime? last_connection { get; set; }

那么在你看来:

@Html.displayFor(x => x.last_connection)

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...