pagination problem with asp.net and partial views

Feb 25 2014 4:31 AM
I have viewmodel with 3 classes


public IEnumerable<Nazivi_grupa> ngrupa { get; set; }
public IEnumerable<Grupe_radova> gradova { get; set; }
public IEnumerable<Pozicije> pozicije { get; set; }

partial view partPozicijeView.cshtml

@model PagedList.IPagedList<WebApplication3.ViewModels.mainViewModel>
@using PagedList.Mvc;

@{ some code to show table }

and main view index.cshtml

@model WebApplication3.ViewModels.mainViewModel
@using PagedList.Mvc;
<tr>
<td>Category&nbsp;</td>
<td>&nbsp;:</td>
<td><div id="KnjigeNormativa">@Html.Partial("partKnjigeNormativaView", Model)</div> </td>
</tr>
<tr>
<td>Sub - Category&nbsp;</td>
<td>&nbsp;:</td>
<td><div id="GrupeRadova"> @Html.Partial("partGrupeRadovaView", Model)</div></td>
</tr>
<tr>
<td>Products&nbsp;</td>
<td>&nbsp;:</td>
<td><div id="Pozicije"> @Html.Partial("partPozicijeView", Model)</div></td>
</tr>

that calls 3 partial views to show first 2 tables in cascaded dropdowns and 3rd one (pozicije) in a table.

Now i'm trying to add pagination to that table, but no matter what, i'm getting an error
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]'.
on 3rd partial view call.

Here's also code for controller

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);
}


I tried (commented code) to return .ToPagedList() but no success...
can someone point me how to do this?