В моей модели у меня есть;
public class ReportDetails
{
public DateTime? MailSent { get; set; }
public DateTime? DateCompleted { get; set; }
}
В моем контроллере;
var query = (from u in SessionHandler.CurrentContext.LennoxSurveyResponses
join c in SessionHandler.CurrentContext.MailingListEntries on u.SurveyCode equals c.SurveyCode
join cl in SessionHandler.CurrentContext.MailingLists on c.MailingListId equals cl.MailingListId
join ch in SessionHandler.CurrentContext.Channels on cl.ChannelId equals ch.ChannelId
join cg in SessionHandler.CurrentContext.ChannelGroups on ch.ChannelGroupId equals cg.ChannelGroupId
where ch.OrganizationId == 8
&& ch.ChannelId == model.ChannelId
select new ReportDetails
{
MailSent = c.LetterDate,
DateCompleted = c.EmailDate
});
model.Report = query.ToList();
Теперь, на мой взгляд, у меня есть
@foreach (var tr in Model.Report)
{
<tr>
<td>@tr.MailSent
</td>
<td>@tr.DateCompleted
</td>
</tr>
Когда отображаются результаты, MailSent
и DateCompleted
имеют дату и время. Я пытаюсь просто отобразить дату без времени. Если я попытаюсь @tr.MailSent.HasValue ? @tr.MailSent.Value.ToShortDateString() : @tr.MailSent;
, тогда я получу ошибку - Value cannot be null
. Как бы я отобразил только часть даты. И MailSent
, и DateCompleted
являются обнуляемыми полями. Заранее спасибо.