2013-10-30 71 views
0

我想知道是否有可能使用mvc web api返回泛型类型。mvc web api get方法返回泛型类型?

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); 
    } 
} 
+0

没关系,你可以例如返回列表。它只是带走了类型铸造,这是一个强大的(方便)功能 – Richard

+2

我想知道为什么你不试试它? – user2674389

回答

1

ASP.NET MVC Web API专为IQueryable和OData查询而设计。只要试试看。