我在详细信息视图页面上收到此错误:
The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies.cpd_certificates_65AF30842281867E2F4F6A1026590271109C12A85C8175394F14EF6DE429CBC7', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[cpd.Models.cpd_certificates]'.
这是我的控制器:
public class Default8Controller : Controller
{
//
// GET: /Default8/
private cpdDbContext db = new cpdDbContext();
public ActionResult Index()
{
return View(db.CPD.ToList());
}
//
// GET: /Default8/Details/5
public ActionResult Details(int id)
{
cpd_certificates cpd_ = db.Cert.Find(id);
return View(cpd_);
}
以下是我的详细信息视图:
@model IEnumerable<cpd.Models.cpd_certificates>
@{
ViewBag.Title = "Details";
}
<h2>Details</h2>
<table>
<tr>
<th>
certificateNo
</th>
<th>
Mark
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.CertificateNo)
</td>
<td>
@Html.DisplayFor(modelItem => item.Mark)
</td>
</tr>
}
</table>
下面是 cpd_certificates 模型:
public class cpd_certificates
{
[Key]
public int CertificateNo { get; set; }
public int QuizNo { get; set; }
public DateTime? DateReceived { get; set; }
public DateTime? DatePaid { get; set; }
public string Mark { get; set; }
public int? AccreditationNo { get; set; }
public int? ID { get; set; }
public virtual cpd_recipients Recipients { get; set; }
}
我有两个模型,我可以在我的索引上查看列表。我打算当我单击详细信息链接时,它会将我带到另一个模型/表格中获得的证书和考试的详细信息。因此,简而言之,两个模型在 CPD 上具有 PK ID,在 Cert 上具有 FK ID。索引页面只显示个人信息,这个页面很好。单击详细信息时,它会显示其他模型/表格数据,即该人的许多证书。