OrderBy takes a lambda expression; in this case, C# inferred one from the string being passed. VB, apparently cannot make that inferrence.
Try using OrderBy(Function(str) sidx + " " + sord)
OrderBy takes a lambda expression; in this case, C# inferred one from the string being passed. VB, apparently cannot make that inferrence.
Try using OrderBy(Function(str) sidx + " " + sord)
Is it possible he's using Dynamic Linq? With dynamic linq you can pass string to the OrderBy methods as well as many other of the IEnumerable extension methods.
I tried to do the same as Kjensen, but i had a lot of problems (including the fact that the original C# sample has some bugs: revisitig the pages some results are ommited). So, i decided to modify the sample of Phil Haack (http://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx) using stored procedures (i never trust in a ORM-thing generating SQL Code, the stored procedure isn't the best but neither the code from Linq) and vb. net (i haven't clean the code and some comments are in spanish)
SQL Code
Create procedure getDataPage1
(@tableName as varchar(100),
@columns as varchar(200),
@columnOrder as varchar(100),
@columnOrderDirection as varchar(20),
@currentPage as int,
@pageSize as int,
@filter as varchar(2000) = '')
AS
BEGIN
-- No se debe referenciar a otras columnas Identity (para esos casos se debe hacer un conversion previa antes de hacer el INSERT INTO)
-- Version válida para Sql server 2000, usar funcion ROW_NUMBER para SQL server 2005 o posterior
-- Ejemplos de uso:
-- exec getDataPage1 'DataTarjetasProcesada', 'linea = cast(linea as varchar(100)), Tarjeta, Bloqueo, Saldo', 'Tarjeta', 'desc', 6, 800
-- exec getDataPage1 'Question', 'Id, Votes, Title', 'Title', 'desc', 2, 10
set nocount on
declare @query as nvarchar(1000)
-- Paso 1: se numera el listado
set @query = 'Select Identifier = Identity(int, 1, 1), ' + @columns +
' into #temp ' +
' from ' + @tableName +
case when @filter = '' then '' else ' where ' + @filter end +
' Order By ' + @columnOrder + ' ' + @columnOrderDirection
-- Paso 2: se toma la página de consulta
+
' select ' + @columns + ' from #temp '+
' where Identifier between ' + cast( @pageSize * (@currentPage -1) + 1 as varchar(15)) +
' and '+ cast (@pageSize*( @currentPage ) as varchar (15))
EXECUTE sp_executesql @query
set nocount off
END
Vb .net Code
Function DynamicGridData(ByVal sidx As String, ByVal sord As String, ByVal page As Integer, ByVal rows As Integer) As ActionResult
Dim context As New MvcTestApplication.modelDataContext
Dim pageIndex As Integer = Convert.ToInt32(page) - 1
Dim pageSize As Integer = rows
Dim totalRecords As Integer = context.Questions.Count()
Dim totalPages As Integer = Math.Ceiling(CDec(totalRecords) / CDec(pageSize))
' Establecemos la función de ordenación dependiendo del valor del
' parámetro "sidx", que es el campo de orden actual
' Establecemos si se trata de orden ascendente o descendente, en
' función del parámetro "sord", que puede valer "asc" o "desc"
Dim results As IMultipleResults = context.getDataPage1("Question", "Id, Votes, Title", sidx, sord, page, pageSize)
Dim questions = results.GetResult(Of Question)()
Dim jsonData = New With { _
.total = totalPages, _
.page = page, _
.records = totalRecords, _
.rows = (From question In questions _
Select New With _
{ _
.i = question.Id, _
.cell = New String() {question.Id.ToString(), question.Votes.ToString(), question.Title} _
} _
).ToArray() _
}
Return Json(jsonData)
End Function