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
  • Thanks.. I guess :-) if you have remarks about the approach, don't hold back. I'm unexperienced at making reuseable/generic stuff like this. Commented May 19, 2009 at 8:40

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.