gpt4 book ai didi

c# - 根据 Date 对表进行排序,在 mvc 4 中使用 Linq 查询

转载 作者:太空宇宙 更新时间:2023-11-03 10:30:50 24 4
gpt4 key购买 nike

我刚刚创建了 mvc 4 应用程序。在那个应用程序中,我有大学表。我想根据创建日期(日期时间)列对此表数据进行排序

enter image description here

这是我用于排序和列出此表的 Ling 查询和 Controller 方法

    [System.Web.Mvc.Authorize]
public ActionResult U_Index(string HEI_ID = null)
{
try
{

var Institutes = from university in db.Institutes
where university.HEI_ID == HEI_ID
select university;

return View(db.Institutes.OrderByDescending(i => i.Create_Date).ToList());
}
catch (Exception ex)
{

return View();
}
}

但这不是按创建数据排序,只是想知道我错过了什么

最佳答案

在返回语句中,您使用的是 db 变量的属性,而不是您刚刚在上面定义的 Institutes 变量。

return View(db.Institutes.OrderByDescending(i => i.Create_Date).ToList());

更改它以使用新变量:

return View(Institutes.OrderByDescending(i => i.Create_Date).ToList());

编辑:将问题改写为有效答案。详细信息提供了一个有效的答案,但被措辞为一个问题。

关于c# - 根据 Date 对表进行排序,在 mvc 4 中使用 Linq 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30316155/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com