我试图在从左到右的流中显示带有短标题的图像,而不是顺序布局的 gridview。我希望使用 webgrid 提供的分页,以免重新创建轮子。
我已经查看了 Leek 的博客文章 (http://msdn.microsoft.com/en-gb/magazine/hh288075.aspx) 和 Broer 的 (http://blog.bekijkhet.com/2011/03/mvc3-webgrid-html -helper-paging.html) 以确保我对 webgrid 的使用有一个扎实的介绍,但是我在如何在不使用 webgrid 的传统布局的情况下应用分页方面存在不足。
我正在使用 Razor 布局。
想法或想法?
我的控制器目前是:
public ActionResult Index(string cid)
{
Catalog item = new Catalog();
item.objConnection.Open();
OdbcDataReader reader = item.getCatalogItems(cid, 3);
List<Catalog> listItems = new List<Catalog>();
while (reader.Read())
{
Catalog i = new Catalog();
i.kitName = reader.GetValue(1).ToString();
i.catalogID = reader.GetValue(0).ToString();
ViewBag.CatalogName = reader.GetValue(0).ToString(); //TODO: change this to name once in place
listItems.Add(i);
}
ViewBag.ItemsPerCatagory = listItems.Count;
reader.Close();
item.objConnection.Close();
return View(listItems);
}
我的观点:
@model IEnumerable<MvcApplication1.Models.Catalog>
@{
ViewBag.Title = ViewBag.CatalogName;
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>@ViewBag.CatalogName (@ViewBag.ItemsPerCatagory) Items Available</h2>
<p>
Category will have a brief description here for seo purposes.
</p>
<p>
@foreach (var catalog in Model)
{
string imageUrl = "http://web3.naeir.org/images/Specials/" + @catalog.kitName + ".JPG";
<img src=@imageUrl height="150px" width="150px" /> @Html.ActionLink(@catalog.kitName, "Details", "Product", new { cid = @catalog.catalogID, itemid = @catalog.kitName }, null)
}
</p>