隐藏的默认值的日期 [英] Hiding the default value for a date

查看:116
本文介绍了隐藏的默认值的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视图模型:

 公共部分类FileTransferFilterCriteriaViewModel
{
    公共字符串FICE {搞定;组; }
    公共字符串SourceEmail {搞定;组; }
    公共字符串TargetEmail {搞定;组; }
    公众的DateTime寄件者{搞定;组; }
    公众的DateTime TODATE {搞定;组; }
    公共字符串状态{搞定;组; }
    公共字符串类别{搞定;组; }
}

(没有什么是从DB来了。)

我的控制器:

 返回查看(新FileTransferFilterCriteriaViewModel())

下面是被显示为寄件者 TODATE

1/1/0001 12:00:00 AM

我的HTML:

  @ Html.TextBoxFor(X => x.Criteria.FromDate)

问题:


  1. 如果日期是,我怎么能燮preSS默认的日期值的显示?

  2. 如果日期是的,我怎么能格式化日期为 MM / DD / YYYY


解决方案

在您的视图模型为空的使用日期:

 公众的DateTime?寄件者{搞定;组; }

My View Model:

public partial class FileTransferFilterCriteriaViewModel
{
    public string Fice { get; set; }
    public string SourceEmail { get; set; }
    public string TargetEmail { get; set; }
    public DateTime FromDate { get; set; }
    public DateTime ToDate { get; set; }
    public string Status { get; set; }
    public string Category { get; set; }
}

(Nothing is coming from the DB.)

My Controller:

return View(new FileTransferFilterCriteriaViewModel())

Here is what gets displayed for both FromDate and ToDate:

1/1/0001 12:00:00 AM

My HTML:

@Html.TextBoxFor(x =>x.Criteria.FromDate)

Questions:

  1. If the date is null, how can I suppress the display of the default date value?
  2. If the date is not null, how can I format the date as MM/dd/yyyy?

解决方案

Use nullable date in your ViewModel:

public DateTime? FromDate { get; set; }

这篇关于隐藏的默认值的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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