이렇게 할 수 있습니다. 전에도 같은 문제가 있습니다.
ArchiveRepository
public IQueryable<ArchiveListModel> AchiveList()
{
var ac = from Post in db.Posts
group Post by new { Post.DateTime.Year
, Post.DateTime.Month }
into dategroup
select new ArchiveListModel()
{
AchiveYear = dategroup.Key.Year,
AchiveMonth = dategroup.Key.Month,
PostCount = dategroup.Count()
};
return ac;
}
컨트롤러
public ActionResult ArchiveBrowse(int AchiveYear, int AchiveMonth, int PostCount)
{
var archivemodel = (from a in db.Posts
where a.DateTime.Year == AchiveYear &&
a.DateTime.Month == AchiveMonth
select a).ToList();
return View(archivemodel);
}
보기
@foreach (var item in Model)
{
@Html.ActionLink(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(item.AchiveMonth) + "" + item.AchiveYear + " (" + item.PostCount + ")",
"ArchiveBrowse", "Post", new
{
AchiveYear = item.AchiveYear,
AchiveMonth = item.AchiveMonth,
PostCount = item.PostCount
}, null)
}
출처
2013-03-21 05:52:51
bot
감사합니다. 내가이 질문을 한 지 한 달이 지났다. 하지만 여전히 도움이됩니다. –