Question

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?

Était-ce utile?

La solution

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>" %>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top