Reputation: 4921
Hi guys I'm currently doing a Blog Archive for my blog. I was able to call the list of blog by Year and Month but my problem is that my Month is displayed in integer. This image will show it
I created a 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;
}
I called it in my Controller
public ActionResult Archive()
{
var archivelst = repository.AchiveList().ToList();
return View(archivelst);
}
then show it in my View
<h2>Archives</h2>
<table>
<tr>
<th>
AchiveYear
</th>
<th>
AchiveMonth
</th>
<th>
PostCount
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@item.AchiveYear
</td>
<td>
@item.AchiveMonth
</td>
<td>
@item.PostCount
</td>
</tr>
}
</table>
How will I convert it to integer? T_T
EDIT:
I tried googling and found this answer
CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(1);
But I don't know where to put it.. :(
Upvotes: 2
Views: 3889
Reputation: 15876
Try it(CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(1);
) in View page
@foreach (var item in Model) {
<tr>
<td>
@item.AchiveYear
</td>
<td>
@System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(item.AchiveMonth)
</td>
<td>
@item.PostCount
</td>
</tr>
}
Upvotes: 6
Reputation: 695
Try this...
AchiveMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(dateGroup.Key.Month),
Upvotes: 0