以下代码位于我的视图中,输出以下内容:
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
查看:
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)
如果ViewBag中有四条记录,那么为什么MvcContrib Grid没有列出它们呢?
这是我的控制器:
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());
}
谢谢。
修改
查看源代码只显示一个空表:
<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>
答案 0 :(得分:0)
我刚用过这个,而不是:
http://msdn.microsoft.com/en-gb/magazine/hh288075.aspx
@{
var grid = new WebGrid(Model, defaultSort:"Name");
}
@grid.GetHtml()