,這是我的行動:做一個列表項結果,反之亦然
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);
}
這就是查看這個動作的結果
@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)
}
輸出是這樣
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
我該怎麼做?
你是怎麼得到這個錯誤的? **不能將void分配給局部變量!** –