我正在尝试获取过去两周内创建的项目列表。我可以检索14项,但我想要14天的项目。我的代码如下所示。我是这种语言的新手,我认为我修复了它但仍有问题。任何帮助都会得到解决
public ActionResult SolaceHistory()
{
var model = new SolaceHistoryList();
model.Statuses = OnlineGivingContext.log_SolaceStatus.OrderByDescending(s => s.DateCreated).Take(14).ToList();
return View(model);
}
答案 0 :(得分:0)
使用以下功能
public ActionResult SolaceHistory()
{
var Criteria=DateTime.Now.AddDays(-14);
var model = new SolaceHistoryList();
model.Statuses = OnlineGivingContext.log_SolaceStatus.OrderByDescending(s => s.DateCreated.Date >= Criteria.Date).ToList();
return View(model);
}
答案 1 :(得分:0)
{
var Criteria = DateTime.Today.AddDays(-14);
var model = new SolaceHistoryList();
model.Statuses = OnlineGivingContext.log_SolaceStatus
.Where(st => st.DateCreated >= Criteria).
OrderByDescending(s => s.DateCreated).ToList();
return View(model);
}
能够解决我的问题