我输出的问题是0001年1月1日。这个细节解释了如果值是0或没有数据,假设日期的数据列也是0或根本没有显示。我正在使用MVC来完成这个程序。
CONTROLLER
return {
'dialogAction': {
'type': 'Close',
'fulfillmentState': 'Fulfilled',
'message': {
'contentType': 'PlainText',
'content': message
},
'responseCard': {
'version': '0',
'contentType': 'application/vnd.amazonaws.card.generic',
'genericAttachments': [
{
'title': 'Here is a list of hospitals',
'subTitle': 'Below is a map',
'attachmentLinkUrl': 'https://www.google.com/maps/search/?api=1&query=nearby+hospitals',
'imageUrl': 'https://images.sftcdn.net/images/t_optimized,f_auto/p/95612986-96d5-11e6-af7c-00163ec9f5fa/3771854867/google-maps-screenshot.png'
},
{
'title': 'Here is a list of medical shops',
'subTitle': 'Below is a map',
'attachmentLinkUrl': 'https://www.google.com/maps/search/?api=1&query=nearby+medical+shops',
'imageUrl': 'https://images.sftcdn.net/images/t_optimized,f_auto/p/95612986-96d5-11e6-af7c-00163ec9f5fa/3771854867/google-maps-screenshot.png'
}
]
}
}
}
MODEL
InventoryItemID = grouped.FirstOrDefault().invItem.InventoryItemId,
QuantityRequest = grouped.Sum(a => (a.invItemj == null ? 0 : a.invItemj.Quantity)),
Status = (grouped.FirstOrDefault().reqj == null) ? string.Empty : grouped.FirstOrDefault().reqj.Status,
LastRequestedDate = (grouped.FirstOrDefault().reqj == null) ? default(DateTime) : grouped.Max(a => a.reqj.RequestDate)
InventoryItemID = inv.InventoryItemId,
ItemName = inv.ItemName,
UnitOfDescription = uom.Description,
ItemCode = inv.ItemCode,
TotalStock = remainingQtyj == null ? 0 :
remainingQtyj.RemainingQuantity,
RequestedQuantity = requestedQtyj == null ? 0 :
requestedQtyj.QuantityRequest,
LastRequestedDate =
requestedQtyj.LastRequestedDate
这是列日期的输出: Stocks With Date
谢谢!
答案 0 :(得分:1)
您可以检查LastRequestedDate.Value
是否为默认日期时间。
如果LastRequestedDate.Value
等于default(DateTime)
,则为空string
public string LastRequestedDateString => (LastRequestedDate.Value == default(DateTime)) ?
string.Empty :
LastRequestedDate.Value.ToString("MMMM dd, yyyy");