如何在CRUD功能中映射复合键 [英] how to map composite key in CRUD functionality
本文介绍了如何在CRUD功能中映射复合键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要基于两个键(comp和part)进行映射.
I need to map based on two keys(comp and 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>
}
如何在索引页面和控制器中使用组合键.
how to use composite key in Index page and also in controller.
public ActionResult Edit(int? id)
{
DataView record = db.RecordDataView.Find(id);
if (record == null)
{
return HttpNotFound();
}
return View(record);
}
如果有人有想法请回复.
If anyone have idea please reply.
推荐答案
find方法通过主键查找实体.如果您有复合主键,请按照在模型中定义的顺序传递键值:
The find method, finds entities by the primary key. If you have a composite primary key, then pass the key values in the order they are defined in model:
@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 })
在控制器中,接收两个值:
In the controller, receive both values:
public ActionResult Edit(int? comp, int? part)
{
DataView record = db.RecordDataView.Find(comp, part);
if (record == null)
{
return HttpNotFound();
}
return View(record);
}
这篇关于如何在CRUD功能中映射复合键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文