【发布时间】:2012-08-31 11:05:15
【问题描述】:
我正在使用支持多语言的数据库。现在的问题是我需要在查询中输入我的语言才能获取信息,这很好,但是存储该信息的最佳方式是什么。
当然,在客户端,它将存储在 cookie 中。现在我能想到的唯一方法是在类上创建全局变量,然后在我的函数中使用它。只有这样吗?
示例代码
private string lang = Infrastructure.UserSettings.Language(); // I don't have this implemented yet
[HttpGet]
public dynamic List()
{
string lang = "English"; // That's why I set it here manually for testing
var items = _db.Items.OrderByDescending(x => x.ID).Select(x => new
{
ID = x.ID,
Price = x.Price,
Name = x.ItemTranslations.Where(y => y.Language.Name == lang).Select(y => y.Name).SingleOrDefault(),
Category = new {
ID = x.Category.ID,
Name = x.Category.CategoryTranslations.Where(y => y.Language.Name == lang).Select(y => y.Name).SingleOrDefault()
}
});
return items;
}
我的问题:这是这样做的好方法还是有更好的方法?
【问题讨论】:
-
您可能希望为不同的语言使用不同的 URL(以获得更好的 SEO、共享等)。 stackoverflow.com/questions/3683404/…
标签: c# asp.net asp.net-mvc asp.net-mvc-4