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.