Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Model:
C#
[Key,Column(Order = 0)]
[ForeignKey("comp")]
public int comp_num { get; set; }
public virtual Comp Comp { get; set; }
[Key, Column(Order = 1)]
[ForeignKey("Master")]
public string part { get; set; }
public virtual Master Master { get; set; }
public string comp_part_num { get; set; }


My Index page:

-----------------------------------------------------------
-----------------------------------------------------------
@foreach (var item in Model) {
@Html.DisplayFor(modelItem => item.comp)
@Html.DisplayFor(modelItem => item.part)
@Html.DisplayFor(modelItem => item.comp_part_num)
@Html.ActionLink("Edit", "Edit", new { id=item.com }) |
@Html.ActionLink("Details", "Details", new { id = item.comp }) |
@Html.ActionLink("Delete", "Delete", new { id = item.comp })
}

when I use only one key in id it gives the error 'The number of primary key value passed must match number of primary key values defined on the entity'

and also give how to use in controller
SQL
public ActionResult Edit(int id = 0)
    {
         RecordDataView record = db.RecordDataView.Find(id);
            if (record == null)
            {
                return HttpNotFound();
            }
            return View(record);
        }


Someone please help.
Posted
Updated 21-Aug-15 1:19am
v3

1 solution

I got resolved it.
just add another parameter to actionlink as

@Html.ActionLink("Edit", "Edit", new { id=item.com, val=item.part })


and in controller

Public Actionlink Edit(int id, string val)
{
RecordDataView record = db.RecordDataView.Find(id,val);
..............
..............
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900