0

I used to do this previously and it worked, but now it shows error, any suggesstion? What does Object reference not set to an instance of an object mean?

@foreach (var item in Model) 
{
    int daysLeft = (item.Membership.PaidDate - DateTime.Today).Days;
    string style = daysLeft <= 7 ? "background-color:Red" : null;
        <tr style="@style">
tereško
  • 58,060
  • 25
  • 98
  • 150
anfield8
  • 33
  • 5
  • may be `item.Membership` or `item.Membership.PaidDate` is null. Check it, if it is not null... – AliRıza Adıyahşi Jun 20 '14 at 05:18
  • Almost all cases of `NullReferenceException` are the same. Please see "[What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)" for some hints. – John Saunders Jun 20 '14 at 18:07

1 Answers1

0

To me it seems item.Membership is NULL

Object reference not set to an instance of object means the variable you are trying to use to get access to an object doesnt have a reference to the object.For example

Employee e;

If without writing e= new Employee(), if i try to get/execute property/method of Employee type then it is an error because e is not referring to any instance of this type.

Prerak K
  • 10,940
  • 7
  • 30
  • 37