2

私はこのテーブルを持っています:

テーブル

friendLINQですべての名前を繰り返しなしで表示したい。どうすればいいのですか?結果は次のとおりです。

martin
kevin
igor

コントローラー:

dbEntities db = new dbEntities();

    public ActionResult Index()
    {
        IQueryable<string> dn = from f in db.table select f.friend;
        IQueryable<string> res = dn.Distinct();
        return View(res);
    }

表示 (ASP.NET MVC 3 Razor):

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.friend)
        </td>
    </tr>
}
4

1 に答える 1

5

Selectとの組み合わせを使用できますDistinct

@foreach (var item in Model.Select(m => m.friend).Distinct()) {
    <tr>
        <td>
            @item
        </td>
    </tr>
}
于 2012-04-21T15:18:31.263 に答える