展会" NULL"在ASP.NET MVC DisplayFor的HTML帮助空值 [英] Show "NULL" for null values in ASP.NET MVC DisplayFor Html Helper

查看:150
本文介绍了展会" NULL"在ASP.NET MVC DisplayFor的HTML帮助空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法得到一个 @ Html.DisplayFor 值在视图中显示NULL如果模型项目的值为

下面是一个项目的一个例子,我详细查看我目前工作的。现在如果显示咱这说明的值为

 < D​​IV CLASS =显示字段>
    @ Html.DisplayFor(型号=> model.Description)
< / DIV>


解决方案

是的,我会建议使用以下数据标注在你的codefirst模型可为空的日期时间字段:

  [显示(NAME =上次连接)]
[DisplayFormat(NullDisplayText =永远连接)]
公众的DateTime? last_connection {搞定;组; }

然后在您的视图:

  @ Html.DisplayFor(X => x.last_connection)

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)

这篇关于展会&QUOT; NULL&QUOT;在ASP.NET MVC DisplayFor的HTML帮助空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆