gpt4 book ai didi

c# - 制作列表项结果 VICEVERSA

转载 作者:行者123 更新时间:2023-11-30 22:16:42 28 4
gpt4 key购买 nike

这是我的 Action :

public ActionResult List()
{
var currentDate = DateTime.Now;
var list = new List<ArchiveViewModel>();
for (var startDate = new DateTime(2012, 11, 1); startDate <= currentDate; startDate = startDate.AddMonths(1))
{
list.Add(new ArchiveViewModel
{
Month = startDate.Month,
Year = startDate.Year,
FormattedDate = startDate.ToString("MMMM, yyyy")
});
}
return View("List",list);
}

这是 View

@model IList<Blog.Web.UI.ViewModels.ArchiveViewModel>

@foreach (var item in Model)
{

@Html.ActionLink(item.FormattedDate, "Post", "Archive", new { month = item.Month, year = item.Year }, null)

}

这个 Action 结果的输出是这样的

November, 2012
December, 2012
January, 2013
February, 2013
March, 2013
April, 2013
May, 2013
June, 2013

但我想在输出中有这样的东西

  June, 2013
May, 2013
April, 2013
March, 2013
...
November, 2012

我该怎么做??

最佳答案

var newList = list.Reverse(); //This will change the order of all records

var newList = list.OrderByDescending(x => x.Year)
.ThenBy(x => x.Month)
.ToList();

关于c# - 制作列表项结果 VICEVERSA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17201902/

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