Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Where is the error
Message
From
01/10/2019 11:22:49
 
General information
Forum:
C#
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01671232
Message ID:
01671288
Views:
37
Hi Naomi, do you have options to check if the rec variable .HasValue before proceed with the next instructions?

John.

>Hi everybody,

>Usually after I post a message I can see the error so hopefully it'll work this time again. I'm converting old style VFP pseudo htm into new Razor syntax.

>This is the line that gives an error that nullable object must have a value. I'm not seeing the error, I think I'm checking all possible conditions, so this error should not happen. What am I missing here?
>
<TD>@rec.IsVoided?"Voided": @(rec.DateOut == null)?"":@(rec.DateIn != null && rec.DateIn.Value > DateTime.Parse("1990-01-01"))? @("Closed: " + @rec.DateIn.Value.ToString("yy-M-d")): @("Still Active")</TD>
>I also tried re-writing it in lots of different ways, but still getting errors.

>UPDATE. I had to re-write it into much more verbose syntax to make it to work. On the other hand, it may be clearer this way:
@if (rec.IsVoided)
            {
                <td>Voided</td>
                <td>Voided</td>
            }
            else
            {
                if (rec.DateOut == null)
                {
                    <td>Pending</td>
                    <td></td>
                }
                else
                {
                    <td>@rec.DateOut.Value.ToString("yy-M-d")</td>
                    if (rec.DateIn==null || rec.DateIn.Value.Year < 1903)
                    {
                        <td>Still Active</td>
                    }
                    else
                    {
                        <td>Closed: @rec.DateIn.Value.ToString("yy-M-d")</td>
                    }
                }
            }
>Thanks in advance.
John Harold Belalcázar Lozano
Associate Director Of Development
http://www.belvicto.co/
jhbelalc@gmail.com
Previous
Reply
Map
View

Click here to load this message in the networking platform