2013-10-30 78 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查詢而設計。只要試試看。