This is a part of my question which I deleted because its too broad
I created a ActionLink for my blog Archive but I'm having trouble with it because I'm calling multiple items inside it.
This is my codes which return an error message No overload for method ActionLink takes 7 arguments
@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)
}
This is my original codes but doesn't have a link it only gives a list
@foreach (var item in Model)
{
<br />
<li> @System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(item.AchiveMonth) @item.AchiveYear (@item.PostCount) </li>
}
</fieldset><br/>
output:
January 2013 (1)
February 2013 (1)
December 2012 (4)
Here's how I do it in my controller but I know its not working. 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;
}
What's the correct way to call multiple items in the view?
What I'm trying here is to view the list of Posts under a specific month and year or something like Blog Archives.
Latest Update(working)
Finally I was able to make it work this is now a working one
Updated 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;
}
Updated Controller
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);
}
Updated View
@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)
}