Asp.net mvc 如何在MVC中对参数化列表进行分页?
我想使用Asp.net mvc 如何在MVC中对参数化列表进行分页?,asp.net-mvc,parameters,paging,Asp.net Mvc,Parameters,Paging,我想使用PagedListmvc在带有参数类别的产品列表中分页 控制器样本 public ActionResult ListProduct(int id, int? pagePos) { var list = db.List_Product.Where(e => e.CategoryID == id); int pageNumber = (pagePos ?? 1); return View(li
PagedList
mvc在带有参数类别的产品列表中分页
控制器样本
public ActionResult ListProduct(int id, int? pagePos)
{
var list = db.List_Product.Where(e => e.CategoryID == id);
int pageNumber = (pagePos ?? 1);
return View(list.ToList().ToPagedList(pageNumber, 2));
}
并且在视图ListProduct.cshtml中
@*@model IEnumerable<Sales.Areas.Users.Models.List_Product>*@
@model PagedList.IPagedList<sales.areas.users.models.list_product> @*Maybe error in line here*@
@using PagedList.Mvc
<table class="table">
<tr>
<th>
Name
</th>
<th>
ID
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.ID)
</td>
</tr>
}
</table>
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, pagePos => Url.Action("ListProduct", new { pagePos }))
@*@model IEnumerable*@
@model PagedList.IPagedList@*此处的行中可能有错误*@
@使用PagedList.Mvc
名称
身份证件
@foreach(模型中的var项目){
@DisplayFor(modelItem=>item.Name)
@DisplayFor(modeleItem=>item.ID)
}
@Model.PageCount的@页(Model.PageCountUrl.Action(“ListProduct”,new{pagePos}))
它不工作,并出现此错误
CS0234:名称空间“pagedlis”中不存在类型或名称空间名称“IPagedLis”(是否缺少程序集引用?
,尽管我以前添加了引用PagedList
。如果没有有关此错误的更多信息,很难找到罪魁祸首。您应该在web.config中禁用自定义错误并激活调试
首先检查是否传递了ActionResult ListProduct中的变量id
那么在你看来,改变:
@model PagedList.IPagedList<sales.areas.users.models.list_product>
@model PagedList.IPagedList
与:
@model PagedList.IPagedList
确保在使用该名称空间中的任何类型之前,先使用所有必要的名称空间
@using PagedList; //import this so we can cast our list to IPagedList (only necessary because ViewBag is dynamic)
@using PagedList.Mvc; //import this so we get our HTML Helper
@model IPagedList<Sales.Areas.Users.Models.List_Product>
@使用页面列表//导入此项,以便将列表强制转换到IPagedList(仅因ViewBag是动态的而必需)
@使用PagedList.Mvc//导入此文件,以便获得HTML帮助程序
@IPagedList模型
@brian大写/小写在C中很重要#不,我已经更改了,但没有效果。亲爱的@Nkosi,我试过了,但不适合我。
@using PagedList; //import this so we can cast our list to IPagedList (only necessary because ViewBag is dynamic)
@using PagedList.Mvc; //import this so we get our HTML Helper
@model IPagedList<Sales.Areas.Users.Models.List_Product>