[英]Sort generic list descending order
我的控制器中有一個方法
public ActionResult Index()
{
return View(db.Posts.ToList());
}
如何按降序排列列表? 喜歡而不是從id:1開始,它從表中的最后一個id開始
public ActionResult Index()
{
return View(db.Posts.OrderByDescending(p => p.Id).ToList());
}
使用Enumerable.OrderByDescending方法
按降序對序列的元素進行排序。
public ActionResult Index()
{
return View(db.Posts.OrderByDescending(r=> r.id).ToList());
}
像這樣的東西:
db.Posts.OrderByDescending(x => x.id).ToList();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.