2

我的控制器中有一个方法

   public ActionResult Index()
    {
        return View(db.Posts.ToList());
    }

如何按降序获取列表?就像不是从 id:1 开始,而是从表中的最后一个 id 开始

4

3 回答 3

5
public ActionResult Index()
    {
        return View(db.Posts.OrderByDescending(p => p.Id).ToList());
    }
于 2013-04-25T11:39:50.647 回答
2

使用Enumerable.OrderByDescending 方法

按降序对序列的元素进行排序。

public ActionResult Index()
{
    return View(db.Posts.OrderByDescending(r=> r.id).ToList());
}
于 2013-04-25T11:40:11.967 回答
1

像这样的东西:

db.Posts.OrderByDescending(x => x.id).ToList();
于 2013-04-25T11:40:36.313 回答