gchq gchq - 1 year ago 83
Vb.net Question

Grid.Mvc.Ajax initialising issues

I am attempting to get Grid.Mvc.Ajax running in a MVC project, but the documentation is very poor. There are two issues as the moment - first one relates the Index ActionResult. I have tried to define a new grid a number of ways but it always throws 'IQueryable(Of DateGridModels)' is an interface type and cannot be used as an expression..

Examples of what I have tried

Dim vGrid = CType(New Grid.Mvc.Ajax.GridExtensions.AjaxGridFactory().CreateAjaxGrid(IQueryable(Of DateGridModels), 1, False, 5), Grid.Mvc.Ajax.GridExtensions.AjaxGrid(Of DateGridModels))

Dim vGrid2 = CType(New AjaxGridFactory().CreateAjaxGrid(Of DateGridModels)(IQueryable(Of DateGridModels), 1, False, 5), AjaxGrid(Of DateGridModels))


The other issue, not directly related to the grid but more general MVC is this

@Html.RenderPartial("_DataGrid", Model)
End Code

Returns 'Expression does not produce a value'

============================ EDIT ========================

In response to Mark C in comments


@Imports GridMvc.Html
@Imports GridMvc.Sorting
@ModelType Grid.Mvc.Ajax.GridExtensions.AjaxGrid(Of DateGridModels)


@ModelType MainModels

Main Model

Public Class MainModels
Public Property CalendarM() As CalendarModels
Public Property GridM() As List(Of MaintGrid)
End Class

Grid Model

Public Class DateGridModels
Public Property FirstName() As String
Public Property LastName() As String
End Class

Answer Source

I would instantiate the Grid exactly as the documentation specifies to do so, like:

Dim vm = New List(Of DateGridModels)() From { _
    New DateGridModels() With { _
        Key .FirstName = "John", _
        Key .LastName = "Doe" _
    } _
Dim ajaxGridFactory = New Grid.Mvc.Ajax.GridExtensions.AjaxGridFactory()
Dim grid = ajaxGridFactory.CreateAjaxGrid(vm, 1, False)

It looks like the list doesnt need to be implemented AsQueryable(), probably because they are doing some linq statements in the Grid.