Question

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*1985@gmail.com) 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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top