Asp.net mvc 3 将整数月转换为其名称

Asp.net mvc 3 将整数月转换为其名称,asp.net-mvc-3,razor,archive,Asp.net Mvc 3,Razor,Archive,大家好,我现在正在为我的博客做一个博客存档。我可以按年份和月份调用博客列表,但我的问题是我的月份显示为整数。此图像将显示它 我创建了一个档案馆 public IQueryable<ArchiveListModel> AchiveList() { var ac = from Post in db.Posts group Post by new { Post.DateTime.Year, Post.Dat

大家好,我现在正在为我的博客做一个博客存档。我可以按年份和月份调用博客列表,但我的问题是我的月份显示为整数。此图像将显示它

我创建了一个档案馆

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;
        }
然后在我的视图中显示它

<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>
但我不知道该把它放在哪里(

在查看页面中尝试(
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>
}
@foreach(模型中的变量项){
@项目1.1年度成绩
@System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(item.AchiveMonth)
@项目1.PostCount
}
在查看页面中尝试它(
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>
}
@foreach(模型中的变量项){
@项目1.1年度成绩
@System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(item.AchiveMonth)
@项目1.PostCount
}
试试这个

AchiveMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(dateGroup.Key.Month),
试试这个

AchiveMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(dateGroup.Key.Month),

添加
System.Globalization.
到那一行。我更新了我的答案,现在我已经成功了,伙计,我现在面临另一个问题。如何将actionLink添加到匿名类型。我想我必须为此打开另一个问题。我不明白,但是的,你打开了另一个问题来解释场景……我正在向li添加actionLink我为查看其下的帖子列表而生成的st个存档。但由于我调用的是匿名类型,因此我遇到了问题..:(添加
System.Globalization.
到那一行。我更新了我的答案,现在我已经成功了,伙计,我现在面临另一个问题。如何将actionLink添加到匿名类型..T我想我必须为此提出另一个问题。我不明白,但是的,你为解释场景提出了另一个问题..我正在将actionLink添加到l我为查看其下的帖子列表而生成的存档列表。但我遇到了问题,因为我调用了匿名类型..:(此行将给出错误。
linq to entities无法识别该方法…
您必须在“ArchiveListModel”类中将“AchiveMonth”的类型更改为字符串。问题是在linq查询中使用函数,您也是对的,如果他想在代码修改后使用类似您的建议,他可以使用。此行将给出错误。
linq to entities无法识别该方法…
您必须在“ArchiveListModel”类中将“AchiveMonth”的类型更改为字符串。问题是在linq查询中使用函数,您也是对的,如果他想在代码修改后使用您的建议,他可以使用。