Asp.Net MVC Create/Update/Delete with composite key

Posted by nubm on Stack Overflow See other posts from Stack Overflow or by nubm
Published on 2010-04-04T20:13:15Z Indexed on 2010/04/04 20:23 UTC
Read the original article Hit count: 604

Filed under:
|

Hi, I'm not sure how to use composite key.

My Categories table has CategoryId (PK,FK), LanguageId (PK,FK), CategoryName

CategoryId | LanguageId | CategoryName
1          | 1          | Car
1          | 2          | Auto
1          | 3          | Automobile
etc.

I'm following this design

The default action looks like

//
// GET: /Category/Edit/5

public ActionResult Edit(int id)
{
    return View();
}

and ActionLink

<%= Html.ActionLink("Edit", "Edit", new { id= item.CategoryId }) %>

Should I use something like

<%= Html.ActionLink("Edit", "Edit", new { id= (item.CategoryId + "-" + item.LanguageId) }) %>

so the url is

/Category/Edit/5-5

and

//
// GET: /Category/Edit/5-5

public ActionResult Edit(string id)
{
    // parse id

    return View();
}

or change the route to something like

/Category/Edit/5/5

Or there is some better way?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about composite-key