generic viewmodel control (MVC)
I am trying to create a generic user control. So I need a user control with a generic parameter.
<%@ Control Language="C#" I开发者_JS百科nherits="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 an IPager<MyClass>
as a model in RenderPartial
and it will still work just fine.
精彩评论