How to implement a partial view with a typical output type

I work through this sample and ran into a problem. To implement pagination, the sample expands the list and adds pagination to it. This list is then used as a model.

In my opinion, 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 on several pages. Of course, this should be a strongly typed representation, but since I cannot use wildcards in C #, I cannot implement it like this:

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

Since I only plan on using the members declared in the PaginatedList and not in the List , I don't need a type.

In the C # method, we could solve this problem with type inference, but how to partially do this?

+4
source share
1 answer

Define an interface containing the pagination properties that you want to use in the partial view. Let your PaginatedList<T> class implement this interface. Imagine your partial view being entered into an 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>" %> 
+3
source

All Articles