I have the below code return an AsQueryable object from the controller. The Search function works with no errors, and the object returned is AsQueryable().
Public Function Search(ssViewModel As VehicleTheftRecoveryVM) As ActionResult Dim siteSearchResults As IQueryable(Of VehicleTheftRecoveryVM) Dim siteSearchViewModel As New VehicleTheftRecoveryVM() If ssViewModel IsNot Nothing Then siteSearchViewModel = ssViewModel End If TryUpdateModel(siteSearchViewModel) Try Dim siteSearchCriteria As VehicleTheftRecoveryVM = SetSearchCriteria(siteSearchViewModel) siteSearchResults = FilterSearchResultsForSearchCriteria(SessionMgr.User.Id, siteSearchCriteria)
Catch ex As Exception Debug.WriteLine(ex.Message) End Try
Return View(siteSearchResults) End Function
Public Function FilterSearchResultsForSearchCriteria(userId As Integer, searchCriteria As VehicleTheftRecoveryVM) As IQueryable(Of VehicleTheftRecoveryVM) Dim siteQuery = NoFilterSearchResults(userId) Try If (Not IsNothing(searchCriteria)) Then
If searchCriteria.StartDate <> Date.MinValue Then siteQuery = siteQuery.Where(Function(site) site.StartDate >= searchCriteria.CreateDate) End If
If searchCriteria.StartDate <> Date.MinValue Then Dim endDate = searchCriteria.StartDate.AddDays(1) siteQuery = siteQuery.Where(Function(site) site.StartDate <= endDate) End If
If Not String.IsNullOrEmpty(searchCriteria.StatusIdString) Then siteQuery = siteQuery.Where(Function(site) site.StatusIdString IsNot Nothing AndAlso site.StatusIdString = searchCriteria.StatusIdString) End If
If Not String.IsNullOrEmpty(searchCriteria.CountyLookupIdString) Then siteQuery = siteQuery.Where(Function(site) site.CountyLookupIdString IsNot Nothing AndAlso site.CountyLookupIdString = searchCriteria.CountyLookupIdString) End If
End If
Return siteQuery.AsQueryable() End Function
However, I'm getting the following error when I the isGrid binds.
infragistics.ui.grid.framework.js:30 Uncaught Error: The remote request to fetch data has failed: ( 500 Internal Server Error ) at $.<computed>.<computed>._renderData (infragistics.ui.grid.framework.js:30) at $.<computed>.<computed>._renderData (VM767 jquery-ui-1.10.4.js:401) at proxy (jquery-2.1.1.js:513) at Class._errorCallback (infragistics.datasource.js:36) at fire (jquery-2.1.1.js:3073) at Object.fireWith [as rejectWith] (jquery-2.1.1.js:3185) at done (jquery-2.1.1.js:8253) at XMLHttpRequest.<anonymous> (jquery-2.1.1.js:8598)
Below is the grid.
function bindSitesGrid() { try { $("#TheftGrid").igGrid({ responseDataKey: 'Records', width: "100%", height: "400", autoGenerateColumns: false, primaryKey: "VTRID", fixedHeaders: true, requestType: "Post", columns: [ { key: "VTRID", headerText: "", hidden: true }, { key: "MRN", headerText: "MRN", dataType: "string", width: "10%" }, { key: "AgencyTrackingNumber", headerText: "Agency Tracking Number", dataType: "string", width: "10%" }, { key: "StartDate", headerText: "Create Date", dataType: "date", width: "10%" }, { key: "Agency", headerText: "Agency", dataType: "string", width: "15s%" }, { key: "StatusId", headerText: "Status", dataType: "string", width: "15s%" }, { key: "County", headerText: "County", dataType: "string", width: "15%" }, { key: "Latitude", headerText: "Latitude", dataType: "string", width: "10%" }, { key: "Longitude", headerText: "Longitude", dataType: "string", width: "10%" }, { key: "ReportLink", headerText: "Report Link", formatter: formatViewSiteDocumentButton, width: "10%" } ], autoGenerateLayouts: false, features: [ { name: 'Sorting', type: 'remote', sortUrlKey: 'sort', sortUrlKeyAscValue: 'asc', sortUrlKeyDescValue: 'desc', columnSettings: [ { columnKey: 'MRN', allowSorting: false } ] }, { name: 'MultiColumnHeaders' }, { recordCountKey: 'TotalRecordsCount', pageIndexUrlKey: 'page', pageSizeUrlKey: 'pageSize', name: 'Paging', type: 'remote', pageSize: portalUI.pageSize(), pageSizeDropDownLocation: 'inpager' } ] });
var parameters = $('#VTRModifiedCriteriaForm').serialize(); var url = '/VTR/VehicleTheftRecovery/Search/?ticks=' + new Date() + "&" + parameters;
$('#TheftGrid').igGrid('option', 'dataSource', url); } catch (error) { console.log(error) }
}
And here are properties of the object bound into the AsQueryable object
searchResults = (From site In DataContext.VtrVehicleTheftRecoveries Group Join countyDistrict In DataContext.CountyDistricts On countyDistrict.CountyLookupId Equals site.CountyLookupId Into countyDistrictGroup = Group From countyDistricts In countyDistrictGroup.DefaultIfEmpty() Group Join countyLookup In DataContext.Lookups On countyDistricts.CountyLookupId Equals countyLookup.Id Into countyLookupGroup = Group From counties In countyLookupGroup.DefaultIfEmpty() Select New VehicleTheftRecoveryVM With { .VTRID = site.Vtrid, .MRN = site.MasterRecordNumber, .AgencyTrackingNumber = site.AgencyTrackingNumber, .StartDate = site.CreatedDate, .Agency = site.AgencyIdNmb, .StatusId = site.VtrStatus, .County = counties.Name, .Latitude = site.Latitude, .Longitude = site.Longitude, .ReportLink = site.LinkMrn }).OrderByDescending(Function(site) site.MRN)
Return searchResults.ToList()
The only errors I'm getting is the http 500 error shown at the top. Is there anyway to get more detailed error messaging?
Hello Ernest,
Thank you for posting in our forum.
The grid has a requestError event, which you can bind to in order to handle scenarios when the remote request has failed:
https://www.igniteui.com/help/api/2019.1/ui.igGrid#events:requestError
In it you can get the error message and response data returned from the server.
Let me know if you have any additional questions or concerns.
Regards,
Maya Kirova
Actually, I do have another question. Currently, my controller function that returns object to the igrid does so as an IQueryable<T> object. Is there anyway that the igrid can use an Json object? Thanks.