1

こんにちはみんな私は現在私のブログのためにブログアーカイブをやっています。ブログのリストを年と月で呼び出すことができましたが、問題は月が整数で表示されることです。この画像はそれを示します
ここに画像の説明を入力してください

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 Archive()
        {
            var archivelst = repository.AchiveList().ToList();
            return View(archivelst);
        }

次に、それを私のビューに表示します

<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>

どうすれば整数に変換できますか?T_T

編集:
グーグルを試してみて、この答えを見つけました

CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(1);

しかし、私はそれをどこに置くべきかわかりません.. :(

4

2 に答える 2

5

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>
}
于 2013-02-13T11:32:01.640 に答える
0

これを試して...

AchiveMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(dateGroup.Key.Month),
于 2013-02-13T11:45:38.637 に答える