2

我不确定如何使用复合键。

我的 Categories 表有 CategoryId (PK,FK)、LanguageId (PK,FK)、CategoryName

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

我按照这个设计

默认操作看起来像

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

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

和 ActionLink

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

我应该使用类似的东西吗

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

所以网址是

/Category/Edit/5-5

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

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

    return View();
}

或将路线更改为类似

/Category/Edit/5/5

或者有什么更好的方法?

4

2 回答 2

4

好吧,这比我想象的要容易:-) 只需将 2 个参数放入 ActionLink 中的 RouteValues 中,它就会生成一个查询字符串。

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

The url will be Category/Edit/1?lang=3

So it's more about routing than anything else in my question. More on this

于 2010-04-04T23:27:46.803 回答
0

是的,有更好的方法。 您还可以从请求中确定用户的语言和文化,以确定要使用数据库中的哪条记录。而且我不会想出像 1 = 英语 2 = 德语这样的随机方案。使用标准的文化标识符。

于 2010-04-04T20:24:19.850 回答