Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dieter Luekens 4 posts 77 karma points
    May 03, 2019 @ 15:02
    Dieter Luekens
    0

    if Model.Value datetime is null

                <p>
                    <time>
                        @if (@Model.Value<DateTime>("handbuchgb") != DateTime.MinValue)
                        {
                            @(Model.Value<DateTime>("handbuchgb").ToString("dd.MM.yyyy"))
                        }
                    </time>
                </p>
    
  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    May 03, 2019 @ 15:55
    Søren Gregersen
    1

    you would normally use value != default(DateTime) for checks like that

    also, your code outputs an empty time tag if the value is not set, and you also call a method multiple times...

    @{
        var handbuchgb = Model.Value<DateTime>("handbuchgb");
    }
    <p>
        @if (handbuchgb!=default(DateTime))
        {
            <time>@handbuchgb.ToString("dd.MM.yyyy")</time>
        }
    </p>
    
Please Sign in or register to post replies

Write your reply to:

Draft