2013-03-14 90 views
0

我有兩個字段日期(日期時間)和交易ID(INT)。在Dropdownlist顯示日期時間值問題剃鬚刀mvc

我需要提取10到20之間的transactionID的日期值並將其顯示在下拉列表中。

我不喜歡..

BFDbEntities BFT = new BFDbEntities(); 

var xe = (from n in BFT.Transactions where n.TRANSACTIONID > 10 where n.TRANSACTIONID < 20 select n.DATE); 

List<int> items = new List<int>(); 

foreach (var item in xe) 
{ 
    **items.Add(item);** 
} 

ViewBag.yearlb = new SelectList(items); 

我收到以下錯誤:

錯誤2的最佳重載的方法匹配 「System.Collections.Generic.List.Add(INT) '有一些無效參數C:\ Users \ Santhosh \ Documents \ Visual Studio 2012 \ Projects \ VS 2010 \ sampleBF \ sampleBF \ Controllers \ HomeController.cs 94 17 sampleBF

Error 3參數1:無法從'Syste m.DateTime?到 '廉政' C:\用戶\ Santhosh \文檔\的Visual Studio 2012 \項目\ Visual Studio 2010 \ sampleBF \ sampleBF \控制器\ HomeController.cs 94 27 sampleBF

我知道它的愚蠢的錯誤。但是,只有一週的經驗的初學者。任何幫助,將不勝感激。

謝謝!

+0

我發現它,因爲我已經使用 列表 items = new List (); 顯示日期時間值。 但是 列表 items = new List ();應該使用 。 :) – Santhosh 2013-03-14 03:29:29

+0

如果可以,請將其作爲答案發布。 – ChrisF 2013-03-14 09:50:31

回答

0

我發現了其因爲我已經使用

List<int> items = new List<int>(); 

顯示日期時間值。但是

List<DateTime> items = new List<DateTime>(); 

應該被使用。 :)