我想爲一個簡單的表JQGrid。從JQGrid與ASP.Net MVC與VB.Net
http://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx
後用VB下通過翻譯版本從
http://www.qa.downappz.com/questions/jqgrid-sorting-in-vb-net-mvc-app.html
我把它修改爲我自己的數據庫,並使用此功能
Public Function SelectGridData(ByVal sidx As String, ByVal sord As String, ByVal page As Integer, ByVal rows As Integer) As ActionResult
Dim context As New IssueDBEntities
Dim pageIndex As Integer = Convert.ToInt32(page) - 1
Dim pageSize As Integer = rows
Dim totalRecords As Integer = context.Issues.Count()
Dim totalPages As Integer = CInt(Math.Ceiling(CSng(totalRecords)/CSng(pageSize)))
Dim jsonData = New With { _
.total = totalPages, _
.page = page, _
.records = totalRecords, _
.rows = (From p In context.Issues _
Order By (p.ID & " " & sord) _
Select New With {.id = p.ID, .cell = _
{p.ID, p.Image_Path, p.Magazine_Type,p.Magazine_Path}}).ToArray()}
Return Json(jsonData, JsonRequestBehavior.AllowGet)
End Function
上來
網格確實顯示沒有任何數據,系統將引發錯誤
錯誤描述說
「無法投類型‘System.Int32’輸入‘System.Object的’。 LINQ到實體僅支持鑄造實體數據模型的基本類型。」
任何幫助表示讚賞,如果這是由於一些基本的誤解,請指導我,我願意做一些艱苦的工作。
謝謝
編輯:終於當過每奧列格的建議代碼
Dim Simple_Object As IQueryable(Of Object)
Dim Second_Simple_Object As IQueryable(Of Object)
Dim My_Array As Array
Dim My_Second_Array As Array
Simple_Object = From p In Context.Issues _
Order By (p.ID & " " & sord) _
Select New With {p.ID, p.Image_Path, p.Magazine_Type, p.Magazine_Path}
My_Array = Simple_Object.ToArray()
Second_Simple_Object = From p In Context.Issues _
Order By (p.ID & " " & sord) _
Select New With {p.ID}
My_Second_Array = Second_Simple_Object.ToArray()
Dim My_Result(0) As My_Record_Type
For i = 0 To My_Array.GetLength(0) - 1
If i > 0 Then
ReDim Preserve My_Result(i)
End If
My_Result(i) = New My_Record_Type
My_Result(i).id = CInt(My_Second_Array(i).ID)
My_Result(i).Cell = {My_Array(i).ID.ToString, My_Array(i).Image_Path.ToString, _
My_Array(i).Magazine_Type.ToString, My_Array(i).Magazine_Path.ToString}
Next
Class My_Record_Type
Public id As Integer
Public Cell As String()
End Class
謝謝你的回覆是的,我通過使它們分開 – skv 2012-04-02 04:04:44
謝謝試過您的解決方案你的答覆,是的我試圖通過使他們分開代碼的解決方案,我不得不創建一個對象來實現這個結果,和JSON似乎罰款與填充數據,但不知何故我的網頁沒有顯示,但我認爲你的建議解決了原來的問題,所以非常感謝你 – skv 2012-04-02 04:15:13
我已經發布了代碼,在其他論壇上,我問了這個問題,因爲我不能在這裏發表http://forums.asp.net/p/ 1786677/4910852.aspx/1?p = True&t = 634689228293174596 – skv 2012-04-02 04:33:40