0


これは、ブログアーカイブ用に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) 

}
4

1 に答える 1

2

months years (postcount)「複数のアイテムを呼び出す」と言ったときはまだはっきりしないので、リストをリンクにしたいと仮定して、これが私の答えです。以下のこの出力を取得するには

January 2013 (1)
February 2013 (1)
December 2012 (4)

item.AchiveMonth文字列をitem.AchiveYear連結できますitem.PostCount

@Html.ActionLink(item.AchiveMonth + " " + item.AchiveYear + " ("+ item.PostCount + ")",
"ArchiveBrowse", 
"Post", 
    new { 
          AchiveYear =  item.AchiveYear, 
          ArchiveMonth = item.AchiveMonth, 
          PostCount = item.PostCount },
 null)

次に、でArchiveBrowse、パラメータが正しく整列していることを確認します。

public ActionResult ArchiveBrowse(string AchiveYear, string ArchiveMonth, string PostCount)
{
     //Not sure if you want to display posts in the clicked month/year
}
于 2013-02-17T12:19:17.940 に答える