这是我的行动
[ChildActionOnly]
public PartialViewResult ArchiveSidebar()
{
var currentDate = DateTime.Now;
var list = new List<string>();
for (var startDate = new DateTime(2013, 5, 1); startDate.Month <= currentDate.Month; startDate = startDate.AddMonths(1))
{
list.Add(startDate.ToString("MMMM, yyyy"));
if (startDate.Month == currentDate.Month)
break;
}
return PartialView("_ArchiveSidebar", list);
}
这是_ArchiveSidebar
@model List<string>
<div class="sidebar">
<h3>Archive</h3>
@foreach (string archive in Model)
{
<ul>
<li>
<h3>{
@Html.ActionLink(archive, "Archive", "Blog",new{month=archive?,year=archive ?},null)
}
</h3>
</li>
</ul>
}
</div>
在上面的视图中,我想获取 List 的元素来调用带有年份和月份参数的归档操作,我怎样才能得到年份和月份???(我放哪里了?)
这是存档操作
public ActionResult Archive(int month, int year)
{
var posts = _blogRepository.GetPostByDate(year, month);
return View(posts);
}