我需要基于两个键(comp 和part)进行映射。
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.comp)
</td>
<td>
@Html.DisplayFor(modelItem => item.part)
</td>
...........................
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.comp }) |
@Html.ActionLink("Details", "Details", new { id = item.comp }) |
@Html.ActionLink("Delete", "Delete", new { id = item.comp })
</td>
</tr>
}
如何在索引页面和控制器中使用复合键。
public ActionResult Edit(int? id)
{
DataView record = db.RecordDataView.Find(id);
if (record == null)
{
return HttpNotFound();
}
return View(record);
}
如果有人有想法请回复。
find 方法通过主键查找实体。如果您有复合主键,则按照模型中定义的顺序传递键值:
@Html.ActionLink("Edit", "Edit", new { comp = item.comp, part = item.part }) |
@Html.ActionLink("Details", "Details", new { comp = item.comp, part = item.part }) |
@Html.ActionLink("Delete", "Delete", new { comp = item.comp, part = item.part })
在控制器中,接收两个值:
public ActionResult Edit(int? comp, int? part)
{
DataView record = db.RecordDataView.Find(comp, part);
if (record == null)
{
return HttpNotFound();
}
return View(record);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)