Asp.net mvc 5 如何在CRUD功能中映射复合键
我需要基于两个键(comp和part)进行映射Asp.net mvc 5 如何在CRUD功能中映射复合键,asp.net-mvc-5,entity-framework-5,composite-key,Asp.net Mvc 5,Entity Framework 5,Composite Key,我需要基于两个键(comp和part)进行映射 如果有人有想法,请回复。find方法通过主键查找实体。如果您有复合主键,则按照在模型中定义的顺序传递键值: @Html.ActionLink("Edit", "Edit", new { comp = item.comp, part = item.part }) | @Html.ActionLink("Details", "Details", new { comp = item.comp, part = item.part }) | @Html
如果有人有想法,请回复。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);
}
在应用上述建议时,我得到了一个错误:
The parameters dictionary contains a null entry for parameter 'isdel' of non-nullable type 'System.Boolean' for method 'System.Web.Mvc.ActionResult Edit(System.Nullable`1[System.Int32], Boolean)' in Controller'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
但根据
我尝试将细节更改为动作签名
public ActionResult Details(int eid,bool isdeleted) //same parameter name as in my Entity Model.
带有复合键的CRUD功能现在正常执行
谢谢@Jelle Oosterbosch非常感谢!4年后仍在帮助人们
The parameters dictionary contains a null entry for parameter 'isdel' of non-nullable type 'System.Boolean' for method 'System.Web.Mvc.ActionResult Edit(System.Nullable`1[System.Int32], Boolean)' in Controller'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
public ActionResult Details(int eid,bool isdeleted) //same parameter name as in my Entity Model.