0

I have severel members on application and for each member I want to create a file. I know it is old questions but I am aware that everythink I made is correct according to my old projects.

This is member class:

public class Kobi
{
    [Key]
    public int KobiId { get; set; }
    public string KobiKodu { get; set; }
    public string KobiUnvan { get; set; }
    public string KobiAddress { get; set; }
    public string KobiVergiNo { get; set; }
    public string KobiVergiDaire { get; set; }
    public ICollection<AktifDokuman> AktifDokumans { get; set; }
}

That is my File class that I use for creating files for each member:

public class AktifDokuman
{
    [Key]
    public int AktifDokumanId { get; set; }
    public string Aciklama { get; set; }
    public string Detay { get; set; }
    public DateTime IslemTarihi { get; set; }
    public DateTime GecerlilikTarihi { get; set; }


    [ForeignKey("Kobi")]
    public int KobiId { get; set; }
    public virtual Kobi Kobi { get; set; }
}

Now I used one to many property I used virtual class to reach member props too..

Here is my view which shows how I take the lines.

 <tbody>
    @foreach (var x in Model)
    {
        <tr>
          <td>@x.Kobi.KobiUnvan</td>
          <td>@x.Aciklama</td>
          <td>@x.Detay</td>
          <td>@x.IslemTarihi</td>
          <td>@x.GecerlilikTarihi</td>
          <td><a href="/AktifDokuman/GetDocument/@x.AktifDokumanId" class="btn btn-success btn-sm">Güncelle</a></td>
          <td><a href="/AktifDokuman/DeleteDocument/@x.AktifDokumanId" class="btn btn- danger btn-sm">Sil</a></td>
       </tr>
   }
</tbody>

But on the index.cshtml that problem occurs and I do not now what should I do. I that line

<td>@x.Kobi.KobiUnvan</td>

**NullReferenceException: Object reference not set to an instance of an object **

Can you please help me.

cugurel
  • 27
  • 1
  • 9
  • Where do you initialize these `Kobi` instances? It seems they are not but since you don't show that code i can't help. Please read carefully every hint in this duplicate: https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it – Tim Schmelter May 29 '21 at 11:06
  • I did not exactly understrand bu in the controller I get values like this var value = c.Kobis.toList(); – cugurel May 29 '21 at 11:08
  • Actually after I checked carefully, I became aware of no mistakes. kobi.KobiUnvan must not be null value becase they have actually value. – cugurel May 29 '21 at 11:15

0 Answers0