8

SQLデータベースの3つのテーブルを使用してグリッドビューでデータを表示したい。

最初にモデルを作成しました

public class common
    {

        public Artist Artist { get; set; }
        public Album Album { get; set; }
        public Genre Genre { get; set; }

    }

次に、これはコントローラーです

 public ActionResult Show1()
    {
        var query = from a in DB.Album
                    join b in DB.Artists
                    on a.ArtistId equals b.ArtistId
                    join c in DB.Genre
                    on a.GenreId equals c.GenreId
                    where (b.ArtistId == 2)
                    select new common { Album = a, Artist = b, Genre = c };
        return View(query.ToList());
    }

}

その後、これは私の見解です

@model IEnumerable<test1.Models.common>


@{
    ViewBag.Title = "Show1";
}

<h2>Show1</h2>

<div>

@{

  var grid = new WebGrid(Model, defaultSort:"Name");

}

@grid.GetHtml()

</div>

しかし、それはデータを表示しませんか?どうすればいいですか?

4

4 に答える 4

0

共通オブジェクト モデルに editorTemplate が必要か、for 文を使用して html テーブルに入力する必要があると思います

例えば...

<table summary="">
    <thead>
        <tr>
            <th></th>
            <th>
                Account No.
            </th>
            <th>
                Customer Name
            </th>
            <th class="SingleCheckBox">
                Is Approved
            </th>
            <th  class="SingleCheckBox">
                Is Locked out
            </th>
            <th>
                Last Login
            </th>
        </tr>
    </thead>
    <tbody>
@for (int i = 0; i < Model.Count(); ++i)
{
    var item = Model[i];
    bool isSelected = item.AccountNo == selectedAccountNo;
    <tr>
        <td>@Html.RadioButton("selectedUserName", item.UserName, isSelected, new { name = "selectedUserName" })</td>
        <td>
            @Html.DisplayFor(model => model[i].UserName)
            @Html.HiddenFor(model => model[i].UserName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Email)
        </td>
        <td class="SingleCheckBox">
            @Html.CheckBoxFor(model => model[i].IsApproved) 
        </td>
        <td class="SingleCheckBox">
            @if (item.IsLockedOut)
            {
                @Html.CheckBoxFor(model => model[i].IsLockedOut);
            }
            else
            {
                @Html.CheckBoxFor(model => model[i].IsLockedOut);
            }
        </td>
        <td class="last-child">
            @(TimeZoneInfo.ConvertTime(DateTime.SpecifyKind(item.LastLoginDate, DateTimeKind.Utc), timeZoneInfo).ToString())
        </td>
    </tr>
}
    </tbody>
</table>
于 2012-09-07T04:49:19.930 に答える