Matthew Knudsen
Matthew Knudsen

Reputation: 213

mvc web api get method to return generic type?

I was wondering if it was possible to return a generic type with mvc web api.

eg can I retrun List<T> and NOT List<int> or is this too crazy?

// adding a little more context 
// Controller
IRepoClassInterface repo = new ReopClassWorker();
public List<T> Get<T>(string date, string chartName)
{
    switch(chartName)
    {
       case "myCoolChartBrah":
       return repo.Get<MyListType>(date);

       case "anotherChart":
       return repo.Get<AnotherListType>(date);
    }
 }

Upvotes: 0

Views: 1003

Answers (1)

Peter Kiss
Peter Kiss

Reputation: 9319

ASP.NET MVC Web API designed to that especially with IQueryable with OData queries. Just give it a try and see.

Upvotes: 1

Related Questions