Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8002447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:22:15+00:00 2026-06-04T16:22:15+00:00

Within my MVC3 app I am trying to create a general class (named DdlGet

  • 0

Within my MVC3 app I am trying to create a general class (named DdlGet below) to call that gets records for a drop down list (DDL). The code below does as intended however I think I’m overbaking the use of the Generic type T – specifically the line indicated below with the ‘//**’

I have the following code in my Controller

private readonly IGeneralReferenceRepository<StatusType> statusTypeRepository;
...
public StatusController() : this(...new StatusTypeRepository()) {}

public StatusController(...IGeneralReferenceRepository<StatusType> statusTypeRepository)
{
    ...
    this.statusTypeRepository = statusTypeRepository;
}
...
public ViewResult Index()
{
    ...
    //**** The line below passes a variable (statusTypeRepository) of the Generic
    //**** type (StatusType) and additionally calls the class (Helper<StatusType>)
    //**** with the Generic
    indexViewModel.StatusTypes = Helper<StatusType>.DdlGet(statusTypeRepository);

Then in my repository (this defines the implementation for getting the records for the DDL from the database [via Entity Framework method]) – note the general reference Generic interface (IGeneralReferenceRepository)

public class StatusTypeRepository : IStatusTypeRepository, IGeneralReferenceRepository<StatusType>
{
    ...
    public IQueryable<StatusType> All
    {
        get { return context.StatusTypes; }
    }

I have an interface (which corresponds to the All method being called above)

public interface IGeneralReferenceRepository<T>
{
    IQueryable<T> All { get; }
}

And a helper class to get the drop down list records and place into the SelectList

public class Helper<T>
{
   public static SelectList DdlGet(IGeneralReferenceRepository<T> generalReferenceRepository)
   {
       return new SelectList(generalReferenceRepository.All, ...);
   }
}

The issue I have is the line indicated in the first code block above – i.e. the call to the eventual implementation that populates the SelectList

indexViewModel.StatusTypes = Helper<StatusType>.DdlGet(statusTypeRepository); 

As explaned above in the comment (prefixed with //**) this passes a Generic statusTypeRepository which defines the type via the line:-

private readonly IGeneralReferenceRepository<StatusType> statusTypeRepository;

However I’m already defining the type in the Helper Generic class (i.e. the Helper class)

The question I have is can I derive one from the other rather than specifying the generic twice in the call. i.e. can I derive the type specified in the statusTypeRepository from the Helper class type or vice versa

Many thanks
Travis

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:22:17+00:00Added an answer on June 4, 2026 at 4:22 pm

    Rather than having the type parameter on your Helper class, you could put it on the methods within like this:

    public class Helper
    {
        public static SelectList DdlGet<T>(IGeneralReferenceRepository<T> generalReferenceRepository)
        {
            return new SelectList(generalReferenceRepository.All, ...);
        }
    }
    

    Then you can just do

    indexViewModel.StatusTypes = Helper.DdlGet(statusTypeRepository); 
    

    and the compiler will handle the type inference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Goal I am trying to deploy an MVC3 application that requires Windows Authentication (specifically
Im want to create a data structure for using within my MVC3 application. The
We have recently developed a library of classes that are used within an MVC3
I have an MVC3 site that needs to handle user posts. I am trying
Can I have an MVC3 area within an MVC2 app? I already have an
I have the following code within a razor mvc3 view that is duplicated in
In MVC3 how would I create a custom attribute to a strongly defined class
I have a MVC3 view that enables the user to create a couple different
I have a controller within MVC3 which needs to return a response code 500
Within the same compilation unit, the C++ standard says that static initialization order is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.