Asp.NET MVC 3 - generic type list in a strongly typed view

708 Views Asked by At

I would like to be able to do a strongly typed view/user control, where the type is a list of generic types. Like so:

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

but is not working, as is actually searching for that type. The reason I need it is because the user control (which is just displaying pagination) will be used with lists of objects of different type, and I don't want to recreate it for each of them.

Any ideas?

1

There are 1 best solutions below

0
On BEST ANSWER

You should have a base class or an interface that the view can use.

class PagedList<T> : PagedList {
  // magic
}

Then in your view

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