【发布时间】:2014-03-26 07:13:33
【问题描述】:
我有 3 个类的视图模型
public IEnumerable<Nazivi_grupa> ngrupa { get; set; }
public IEnumerable<Grupe_radova> gradova { get; set; }
public IEnumerable<Pozicije> pozicije { get; set; }
局部视图partPozicijeView.cshtml
@model PagedList.IPagedList<WebApplication3.ViewModels.mainViewModel>
@using PagedList.Mvc;
@{ some code to show table }
和主视图 index.cshtml
@model WebApplication3.ViewModels.mainViewModel
@using PagedList.Mvc;
<tr>
<td>Category </td>
<td> :</td>
<td><div id="KnjigeNormativa">@Html.Partial("partKnjigeNormativaView", Model)</div> </td>
</tr>
<tr>
<td>Sub - Category </td>
<td> :</td>
<td><div id="GrupeRadova"> @Html.Partial("partGrupeRadovaView", Model)</div></td>
</tr>
<tr>
<td>Products </td>
<td> :</td>
<td><div id="Pozicije"> @Html.Partial("partPozicijeView", Model)</div></td>
</tr>
调用 3 个局部视图以显示级联下拉列表中的前 2 个表和表中的第 3 个 (pozicije)。
现在我正在尝试向该表添加分页,但无论如何,我都会遇到错误
The model item passed into the dictionary is of type 'WebApplication3.ViewModels.mainViewModel', but this dictionary requires a model item of type 'PagedList.IPagedList`1[WebApplication3.ViewModels.mainViewModel]'.
第三次局部视图调用。
这里还有控制器的代码
public ActionResult SelectPozicije(string SelectedPosId, int? pnum)
{
int pageNumber = (pnum ?? 1);
mainViewModel mv = new mainViewModel();
mv.pozicije = new List<Pozicije>();
// mv.pozicije = (from p in mainViewModel.getPozicije()
// where p.grupa == SelectedPosId
// select p).ToPagedList(pageNumber, 25);
mv.pozicije = (from p in mainViewModel.getPozicije()
where p.grupa == SelectedPosId
select p).ToList();
return PartialView("partPozicijeView", mv);
}
我尝试(注释代码)返回 .ToPagedList() 但没有成功...
有人能指点我怎么做吗?
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-4 razor pagination