6

I have a view that takes a PaginatedList (like in Nerd Dinner sample). The page works as intended. Now I have added a partial view that takes the same PaginatedList and I call RnederPartial inside the first view. ASP.NET throws a exception that I can't seem to resolve.

PaginatedList Code:

public class PaginatedList<T> : List<T>
{
    public int PageIndex { get; private set; }
    public int PageSize { get; private set; }
    public int TotalCount { get; private set; }
    public int TotalPages { get; private set; }

    public PaginatedList(IQueryable<T> source, int pageIndex, int pageSize)
    {
        PageIndex = pageIndex;
        PageSize = pageSize;
        TotalCount = source.Count();
        TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
        this.AddRange(source.Skip(PageIndex * PageSize).Take(PageSize));
    }

    public bool HasPreviousPage
    {
        get
        {
            return (PageIndex > 0);
        }
    }

    public bool HasNextPage
    {
        get
        {
            return (PageIndex + 1 < TotalPages);
        }
    }
}

Controller:

[Authorize]
public ActionResult Index(int? page)
{
    const int pageSize = 10;

    var workstations = itilRepository.FindAllWorkstations();

    var paginatedWorkstations = new PaginatedList<Workstation>(workstations, page ?? 0, pageSize);

    return View("Index", paginatedWorkstations);
}

Top of Index View:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ITILDatabase.Helpers.PaginatedList<ITILDatabase.Models.Workstation>>" %>

I call the partial view in the Index view as follows:

<% Html.RenderPartial("Workstations", Model); %>

Top of Workstations Partial View:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewPage<ITILDatabase.Helpers.PaginatedList<ITILDatabase.Models.Workstation>>" %>

The error I receive is:

c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\d2889d23\c6192b3e\App_Web_workstations.ascx.a8d08dba.tgrd74s0.0.cs(156): error CS0030: Cannot convert type 'ASP.views_home_workstations_ascx' to 'System.Web.Mvc.ViewUserControl'

If anyone knows why I am getting this error I would greatly appreciate it.

Thank You!

1
  • Just wanted to tell that's not a good idea to steal this PaginatedList code 1:1. It demands all items to be fetched from database. Commented Jun 22, 2009 at 16:14

1 Answer 1

24

Your Workstations Partial View's top should look like:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ITILDatabase.Helpers.PaginatedList<ITILDatabase.Models.Workstation>>" %>

Change ViewPage to ViewUserControl

Sign up to request clarification or add additional context in comments.

3 Comments

I noticed this, but could not remember what it should be like. ^^
Thank You, I can't believe I didn't see that!
Thx, same problem for me, was VS created the control as System.Web.Mvc.ViewPage not ViewUserControl.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.