I am trying to implement IPagedList with a viewmodel, my main view declaration is
@model PagedList.PagedList<CustomerOrders.WebUI.Models.SiteAdminListViewModel>
Then i have a Display Template which has the following declaration
@model CustomerOrders.WebUI.Models.SiteAdminListViewModel
In my controller i am passing the viewmodel to the view
return View(new SiteAdminListViewModel(customerSites.ToPagedList(pageIndex, pageSize), customers.ToPagedList(pageIndex, pageSize)));
This results in an error, "this dictionary requires a model item of type 'PagedList.PagedList'PagedList.PagedList
1[CustomerOrders.WebUI.Models.SiteAdminListViewModel]'
I understand what the error is saying but im unsure how to ammend the viewmodel to incoporate the PagedList, has anyone else experienced this or can anyone point me in the right direction?
Edit////////////////
This is my viewmodel
public class SiteAdminListViewModel
{
public IEnumerable<CustomerSite> CustomerSites { get; set; }
public IEnumerable<Customer> Customers { get; set; }
public Customer Cust { get; set; }
public CustomerSite CustSite { get; set; }
public bool HasPreviousPage { get; set; }
public bool HasNextPage { get; set; }
public int PageCount { get; set; }
public int PageNumber { get; set; }
public SiteAdminListViewModel()
{
}
public SiteAdminListViewModel(IEnumerable <CustomerSite> customerSites, IEnumerable<Customer> customers)
{
CustomerSites = customerSites;
Customers = customers;
}
}
This is a snippet of the display template////////////
@model CustomerOrders.WebUI.Models.SiteAdminListViewModel
@using (Html.BeginForm())
{
<p class="search-controls">
Find site by postcode: @Html.TextBox("SearchString")
<input type="submit" value="Search" /></p>
}
<td>
@Model.CustSite.CustomerSiteId
</td>
<td>
@Html.ActionLink(Model.Cust.CustomerName, "Edit", new { Model.CustSite.CustomerSiteId })
</td>
<td>
@Model.CustSite.AddressLine1
</td>
<td>
@Model.CustSite.Town
</td>
Here is one example I found that uses ViewModel with PagedList.
http://czetsuya-tech.blogspot.com/2011/05/mvc3-dynamic-search-paging-using.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With