これは、ブログアーカイブ用にActionLinkを作成したので、広すぎるために削除した質問の一部ですが、その中の複数のアイテムを呼び出しているため、問題が発生しています。
これはエラーメッセージを返す私のコードですメソッドActionLinkのオーバーロードは7つの引数を取りません
@model IEnumerable <Project.Models.ArchiveListModel>
@foreach (var item in Model)
{
<br />
@Html.ActionLink(item.AchiveMonth, item.AchiveYear, item.PostCount, "ArchiveBrowse", "Post",
new { AchiveYear = item.AchiveMonth, ArchiveMonth = item.AchiveYear, PostCount = item.PostCount }, null)
}
これは私の元のコードですが、リストを提供するだけのリンクはありません
@foreach (var item in Model)
{
<br />
<li> @System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(item.AchiveMonth) @item.AchiveYear (@item.PostCount) </li>
}
</fieldset><br/>
出力:
January 2013 (1)
February 2013 (1)
December 2012 (4)
これが私のコントローラーでそれを行う方法ですが、私はそれが機能していないことを知っています。T_T
public ActionResult Archive()
{
var archivelst = repository.AchiveList().ToList();
return View(archivelst);
}
//this one below is not working
public ActionResult ArchiveBrowse(string archive)
{
var achivemodel = db.Posts.Include("Posts").Single(a => a.Title == archive);
return View(achivemodel);
}
return View(achivemodel);
My 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;
}
ビュー内の複数のアイテムを呼び出す正しい方法は何ですか?
私がここで試しているのは、特定の月と年、またはブログアーカイブのようなものの下の投稿のリストを表示することです。
最新の更新(動作中)
ついに動作させることができましたこれは動作中の
更新された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)
}