I am trying to create a generic user control.
So I need a user control with a generic parameter.
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IPager<T>>" %>
The control doesn’t really care what the T is. It works with any T.
When I render the control, I can instantiate it with the generic argument.
<%= Html.RenderPartial<MyClass>("Pager", Model); %>
That’s the basic idea – is there any way to make a user control that takes an extra generic argument. If I wanted to build such a thing, where would I start?
Any thoughts?
If you are using .NET 4.0, you can use
IPager<object>in the<%@Control %>declaration. Then, the covariant generics support means that you can pass it anIPager<MyClass>as a model inRenderPartialand it will still work just fine.