Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
Grid crashes when datasource function returns zero results

I have my grid set up with a datasource pulling from an ADO .NET Entity Framework model. 


model.GridModel.DataSource = _db.InstrumentLists.Where(clause, SearchTerm)
                                                                .OrderBy(x => x.Tag)


@( Html.Infragistics().Grid("InsrumentListGrid", Model.GridModel)


I am setting the DataSource and not the DataSourceUrl on purpose - all the paging, filtering and sorting is done client side.

The records that are pulled out depend on a search string, hence the Where clause.  If the result of the call is zero records, the grid crashes with a Null Reference Exception.

Here's the top of the stack:

[NullReferenceException: Object reference not set to an instance of an object.]
   Infragistics.Web.Mvc.GridModel.CheckNullables() +341
   Infragistics.Web.Mvc.GridModel.DataBind() +1173
   Infragistics.Web.Mvc.InfragisticsSuite`1.Grid(String id, IGridModel gridViewModel) +278
   ASP._Page_Views_InstrumentList_Index_cshtml.Execute() in c:\Users\DNatoli\Documents\Visual Studio 2010\Projects\ICMDB\ICMDB\Views\InstrumentList\Index.cshtml:39
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +207
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +81
   System.Web.WebPages.StartPage.RunPage() +19