Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4596650
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:08:42+00:00 2026-05-21T23:08:42+00:00

In my model, i have; public class ReportDetails { public DateTime? MailSent { get;

  • 0

In my model, i have;

public class ReportDetails 
{
    public DateTime? MailSent { get; set; }
    public DateTime? DateCompleted { get; set; }
}

In my controller;

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();

Now in my view, I have

@foreach (var tr in Model.Report)
                {
                    <tr>
                        <td>@tr.MailSent
                        </td>
                        <td>@tr.DateCompleted
                        </td>
                    </tr>

When the results are displayed, the MailSent and DateCompleted have both date and time. I am trying to just display the Date without the Time. If I try @tr.MailSent.HasValue ? @tr.MailSent.Value.ToShortDateString() : @tr.MailSent; then i get an error – Value cannot be null. How would i display just the date part. Both MailSent and DateCompleted are nullable fields. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T23:08:43+00:00Added an answer on May 21, 2026 at 11:08 pm

    You have two options:

    an extension method:

    public static MvcHtmlString ShortDate(this DateTime? dateTime)
    {
        if (dateTime.hasValue)
            return MvcHtmlString.Create(dateTime.ToShortDateString());
        else
            return MvcHtmlString.Create("Your other option");
    }
    
    View usage:
    <td>@tr.MailSent.ShortDate()</td>
    

    or inline:

    @(tr.MailSent.HasValue ? @tr.MailSent.Value.ToShortDateString() : DateTime.Now.ToString())
    

    or a default value

    @tr.MailSent.GetValueOrDefault().ToShortDateString()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.