我有这个代码
List<SelectListItem> list = new List<SelectListItem>()
{
new SelectListItem() { Text = "bob", Value = "bob"},
new SelectListItem() { Text = "apple", Value = "apple"},
new SelectListItem() { Text = "grapes", Value = "grapes"},
};
这将用于与 asp.net mvc html 帮助程序进行绑定(bind)。但是我想在绑定(bind)之前对其进行排序。我该怎么做?
最佳答案
如果可以使用 LINQ,那么:
list.OrderBy(x => x.Value)
或
list.OrderByDescending(x =>x.Value)
应该这样做。
编辑
应该这样读;
list = list.OrderBy(x => x.Value);
关于c# - 如何对 ASP.NET MVC 下拉列表进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1698266/