asp.netasp.net-mvcmvccontribmvccontrib-grid

MvcContrib Grid not listing data, despite it's existence


The following code, located in my view, outputs the following:

ViewBag.Count = 4
39d3fe7f-fb1c-4c0f-948e-43093f1d7f85    265ca3c1-9890-4680-b10c-8c7c5e22b26f
f07f0aee-3948-473a-873f-74d446030d36    229db054-e62c-4981-878e-cd0bd5c9a1ac
a92440cd-9393-4d1b-abfb-e705ea739c59    4cd997cf-1715-43b0-9354-0ddf90f33fe6
7c265ae0-7c8e-4dd3-ae76-f52e95138b6e    45254c9a-f078-4d50-bdc8-3e823bdcce41

View:

ViewBag.Count = @ViewBag.Count
<table>
@foreach (var item in Model)
{
    <tr>
        <td>@item.ID</td>
        <td>@item.USER_ID</td>
    </tr>
}
</table>
@Html.Grid(Model)

If there are four records in the ViewBag, then why is MvcContrib Grid not listing them?

Here is my controller:

    public ActionResult Index()
    {
        ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

        ViewBag.Count = db.Directories.Count();

        return View(db.Directories.ToList());
    }

Thank you.

Edit:

A look at the source code shows just an empty table:

<table class="grid"><thead><tr></tr></thead><tbody><tr class="gridrow"></tr><tr class="gridrow_alternate"></tr><tr class="gridrow"></tr><tr class="gridrow_alternate"></tr></tbody></table>

Solution

  • I just used this, instead:

    http://msdn.microsoft.com/en-gb/magazine/hh288075.aspx

    @{
    
      var grid = new WebGrid(Model, defaultSort:"Name");
    
    }
    
    @grid.GetHtml()