【发布时间】:2011-02-25 21:24:54
【问题描述】:
我在 sitefinity 中有一个返回类别列表的函数。
//return list of categories
private IList<ICategory> GetCategoryDataSource() {
var cntManager = new ContentManager(CaseStudyManager.DefaultContentProvider);
IList allCategories = cntManager.GetCategories();
List<ICategory> filteredList = new List<ICategory>();
foreach (ICategory category in allCategories) {
filteredList.Add(category);
}
return filteredList;
}
我想知道的是如何对这个列表进行排序。
据我所知,Sitefinity 中的类别只是一个字符串,没有与类别关联的其他字段。因此,除了为每个类别附加一个数字之外,我没有什么可以对类别进行排序的,例如:
1 - Legal
2 - Financial
3 - Property
当这些类别显示在网站上时,我至少可以修剪我需要的部分。
有人可以帮忙排序吗?
谢谢 铝
【问题讨论】:
-
这不能回答您的问题,但您可以删除您的 foreach / add 语句并将其替换为:filteredList.AddRange(allCategories)
-
ICategory 接口中没有其他属性?没有可以使用的 Id 或 CategoryId?
return filteredList.OrderBy(x => x.CategoryId).ToList()
标签: c# asp.net linq sitefinity