MVC 查看可为空的日期字段格式
我试图在视图中显示以下内容,但出现了问题:
<td>
@item.CreatedByDt.ToString("MM/dd/yyyy")
</td>
有关如何处理视图中可为空的日期字段的任何想法。顺便说一句,我正在使用 Razor。
我收到以下错误:
方法“ToString”没有重载,需要 1 个参数
I am trying to display the following in a view but is giving a problem:
<td>
@item.CreatedByDt.ToString("MM/dd/yyyy")
</td>
Any idea on how to handle a nullable Date field in a view. I am using Razor by the way.
I am getting the following error:
No overload for method 'ToString' takes 1 arguments
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您不知道它是否为空......
If you don't know if it will be null or not...
您可以将日期为空时的显示字符串替换为您想要的内容。
You can replace the display string for when your date is null with what you want.
如果
DateTime?
为空值,则会给出错误。此解决方案不会产生错误:
If
DateTime?
is a null value, they give an error.This solution will not generate an error:
需要那里的价值
need the value in there