【发布时间】:2021-08-08 19:39:30
【问题描述】:
我有两个模型。我如何从视图中访问 FK 值或者我应该如何去做? HTML 页面什么也没有出现。
模型 1:
public class Ogrenci
{
public int OgrenciID { get; set; }
public int OgrenciNumarasi { get; set; }
public string Ad { get; set; }
public string Soyad { get; set; }
public string Bolum { get; set; }
public short Sinif { get; set; }
public string Yetenekler { get; set; }
public string Sifre { get; set; }
public List<Proje> Projeler { get; set; }
}
模型 2:
public class Proje
{
public int ProjeID { get; set; }
public string ProjeAdi { get; set; }
public string Aciklama { get; set; }
public DateTime EklenmeTarihi { get; set; }
public int OgrenciID { get; set; }
public Ogrenci Ogrenci { get; set; }
}
控制器:
public ActionResult Index()
{
return View(db.Projeler.ToList());
}
查看:
@model IEnumerable<DonemProjesi.Models.Proje>
@{
ViewBag.Title = "Index";
}
@Html.DisplayFor(modelItem => item.Ogrenci.Ad) //the problem is here
【问题讨论】:
标签: c# asp.net-mvc entity-framework model-view-controller