4

I am working through this sample and came across a problem. To implement pagination, the sample extends list and adds pagination to it. This list is then used as the model.

In my view I want to add a pagination control. In the sample they simply add it to the page but I want to make it a user control because I plan to implement pagination in multiple pages. Off course This has to be a strongly typed view but since I can't use wildcards in C# I can not implement it like this:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<PaginatedList<?>>" %>

Since I only plan to use the members declared in PaginatedList and not in List I don't need the type.

In a C# method we could solve this problem with type inference but how is it don in a partial view?

1 Answer 1

3

Define an interface containing the pagination properties that you want to use in your partial view. Have your PaginatedList<T> class implement this interface. Have your partial view be typed to the interface.

public interface IPaginated
{
    int PageIndex  { get; }
    int PageSize   { get; }
    int TotalCount { get; }
    int TotalPages { get; }
}

public class PaginatedList<T> : List<T>, IPaginated
{
   ... should not need to change ...
}

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IPaginated>" %>
Sign up to request clarification or add additional context in comments.

Comments

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.