如何在ASP.NET MVC 4/5中使用每个类别的产品列表中的分页

时间:2015-06-18 12:03:07

标签: asp.net asp.net-mvc asp.net-mvc-4 asp.net-mvc-5

我想在用户点击类别链接时显示每个类别的产品列表,然后链接将如下所示:

/Warehouse/Browse?category=Film

//Warehouse controller used to display the product list

WarehouseController中的我的浏览操作将

public ActionResult Browse(string category)
{

    var cat = db.Categories.Include("Products").Single(c => c.CategoryName == category);
    return View(cat);
}

类别模型类:

public class Category
{
    public int CategoryId { get; set; }
    public string CategoryName { get; set; }
    public virtual ICollection<Product> Products { get; set; }
}

产品型号类:

public class Product
{
    public int ProductId { get; set; }
    public string ProductName { get; set; }
    public int CategoryId { get; set; }
    public virtual Category Category { get; set; }
}

如何在浏览视图中使用分页?

0 个答案:

没有答案