views:

667

answers:

1

I'm building a generic grid to use in ASP.NET MVC applications. I'm having troubles with making a partial view that gets a generic class passed to it.

I have prepared a small sample project which demonstates what I want to do. Download it here.

In the HomeController I have 2 controller actions that use my generic grid class to prepare Employee and Department data to be showed by the reuseable partial view /Shared/SimpleTrustGridViewer.ascx.

The problem is that I currently only get the Employees controller action to work when I make the partial view inherit like this:

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

The Departments controlleraction will throw the error i'm stuck on.

I'm hoping someone can take a look at the sample project I prepared and can come up with an easy simple way to make the partial view work for both Employees and Departments. There is no database required or anything, I just use fake repositories.

You can copy paste the fixing code here or link or mail (myUserNameWithoutSpace[email protected]) the fixed sample project.

Any help is much appreciated!

(This is a follow up on this question, as I was unable to get a good answer there. I have prepared a sample project now that you can use to demonstrate what needs to be done.)

Edit: Don't mind the IColumn and ITrustGrid interfaces too much, I played around a bit with those while trying to fix the problem.

+1  A: 

Extend a method like .getTrustGrid() so you can get the same type you need.

MichaelD
I actually have worked out a solution that uses a .GetTrustGrid() to get a non-generic TrustGrid class. I'll post it when I'm done testing it.
Thomas Stock