title: Generic partial view: how to set a generic class as model?
body: <p>I'm trying to build a generic grid view in an ASP.NET MVC application.</p>
  
  <p>Let me explain with some code:</p>
  
  <pre><code>public interface ITrustGrid&lt;T&gt;
  {
      IPagedList&lt;T&gt; Elements { get; set; }
      IList&lt;IColumn&lt;T&gt;&gt; Columns { get; set; }
      IList&lt;string&gt; Headers { get; }
  }
  </code></pre>
  
  <p>This is an interface of a class that allows me to set columns and expressions in my controller. </p>
  
  <p>I pass implementations to a partial view like this:</p>
  
  <pre><code>&lt;% Html.RenderPartial("SimpleTrustGridViewer", ViewData["employeeGrid"] as TrustGrid&lt;EmployeeInfoDTO&gt;); %&gt;
  </code></pre>
  
  <p>The problem is that I can't figure out how to make the partial view that renders the grid generic.</p>
  
  <p>In other words, I want to turn this:</p>
  
  <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;ITrustGrid&lt;EmployeeInfoDTO&gt;&gt;" %&gt;
  </code></pre>
  
  <p>into something like this:</p>
  
  <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;ITrustGrid&lt;T&gt;&gt;" %&gt;
  </code></pre>
  
  <p>=> How can I make my partial view generic in the most simple way?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I solved this by using a TrustGridBuilder that has a public TrustGrid GetTrustGrid() method which returns a non-generic TrustGrid. The TrustGrid contains strings instead of linq stuff. So I execute the linq in the GetTrustGrid() method and put the strings in a TrustGrid object.</p>
  
  <p>Thanks for everybody to help me on the right track.</p>