2012-01-09 56 views
0

我需要用口不重複的記錄,但我有一個錯誤:鮮明的嘴LINQ2SQL

Column "data" does not exist.

Server Error in '/' Application. 
Column "data" does not exist. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: Column "data" does not exist. 

Source Error: 

Line 14:  var grid = new WebGrid(ViewBag.dat ,null, "Dates", 8); 
Line 15:    } 
Line 16: @grid.GetHtml(
Line 17:   tableStyle: "grid", 
Line 18:   headerStyle: "head", 

我的控制器:

var d = (from b in baza.hours 
     where b.userID == userID 
     select new { b.data.Month }).Distinct(); 

      ViewBag.dat = d; 

而我的觀點:

@using (Html.BeginForm()) { 
    @Html.ValidationSummary(true) 
    <fieldset> 
     @{ 
    var grid = new WebGrid(ViewBag.dat ,null, "Dates", 8); 
     } 
@grid.GetHtml(
     tableStyle: "grid", 
     headerStyle: "head", 
     alternatingRowStyle: "alt", 
     columns: grid.Columns(
       grid.Column("data","Dates")    

    ) 
     ) 

    </fieldset> 
} 

如何解決?

+0

如果您可能包含您收到的錯誤,將會很有幫助。 – 2012-01-09 22:57:19

+0

我的猜測是你的專欄是日期不是數據..仔細檢查你的linq – 2012-01-09 22:58:41

+0

@PhilKlein我把錯誤。 @BassamMehanni,這不是一個問題:)當我使用'b.data'而不是'b.data.Month'一切正常。數據是電子波蘭名稱日期,列是電話數據。 – user1031034 2012-01-09 23:09:43

回答

0

嘗試這樣的:

grid.Column("Month", "Dates") 

你是返回一個匿名對象到您的視圖。或者更確切地說是一組匿名對象,每個對象都有一個名爲Month的屬性。所以你應該在你的標記中使用Month作爲列名。