bot*_*bot 1 archive razor asp.net-mvc-3
大家好,我目前正在为我的博客制作博客档案。我可以按年和月调用博客列表,但我的问题是我的月以整数显示。这张图片将显示它

我创建了一个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;
}
Run Code Online (Sandbox Code Playgroud)
我在我的控制器中调用它
public ActionResult Archive()
{
var archivelst = repository.AchiveList().ToList();
return View(archivelst);
}
Run Code Online (Sandbox Code Playgroud)
然后在我的视图中显示它
<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>
Run Code Online (Sandbox Code Playgroud)
我将如何将其转换为整数?T_T
编辑:
我尝试谷歌搜索并找到了这个答案
CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(1);
Run Code Online (Sandbox Code Playgroud)
但我不知道把它放在哪里..:(
CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(1);在查看页面中尝试 ( )
@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>
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3628 次 |
| 最近记录: |