views:

1215

answers:

1

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!

+7  A: 

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

eu-ge-ne
I noticed this, but could not remember what it should be like. ^^
Arnis L.
Thank You, I can't believe I didn't see that!
Lukasz