简体   繁体   English

Blazor 服务器端应用程序日期时间默认为 01/01/0001

[英]Blazor Serverside Application Datetime default to 01/01/0001

I tried to make my CreatedDate column to be null or at least show the current date when I launch the application instead of 01/01/0001.我试图让我的 CreatedDate 列为空或至少在我启动应用程序时显示当前日期而不是 01/01/0001。 I tried the example in Format MVC default Date (01/01/0001) to be empty and by adding a dot notation "newPerson.StartDate.Now" to the column on the razor page which wasn't working either.我尝试将Format MVC default Date (01/01/0001) 中的示例设置为空,并在 razor 页面上的列中添加点符号“newPerson.StartDate.Now”,该列也不起作用。

public DateTime? MyDate { get; set; }

In your constructor of your object:在对象的构造函数中:

MyDate = null;

Or if you want to use a date或者,如果您想使用日期

MyDate = DateTime.Now;

I just tested and both work for me.我刚刚测试过,两者都对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM